# Apply FocusedValue for Active macOS Scenes Only in SwiftUI

You have just created the [world's best Lyric writing app for macOS](https://lyrcs.app).

You get your first feature request; **printing**. Easy enough because you've heard you can add `commands` to your `Scene`:

```swift
struct ExampleApp: App {
    var body: some Scene {
        DocumentGroup(newDocument: AppDocument()) { file in
            ContentView(document: file.$document)
        }
        .commands {
            CommandGroup(replacing: .printItem) {
                Button("Print...") {
                    // ...
                }
                .keyboardShortcut("p", modifiers: [.command])
            }
        }
    }
}
```

You even throw in a cheeky shortcut because you care about making the lives of your users easier.

But wait a second, how does the app know which document to print given a user can have multiple documents opened at the same time.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1714893473833/83437a9c-8cd0-4d82-bbaf-11c861a6cdd2.jpeg align="center")

Please welcome `focusedSceneValue(...)` to the stage 👏

Let's get started:

1. Create a Focused Value
    

```swift
extension FocusedValues {
    enum PrintValueKey: FocusedValueKey {
        typealias Value = () -> Void
    }

    var print: PrintValueKey.Value? {
        get { self[PrintValueKey.self] }
        set { self[PrintValueKey.self] = newValue }
    }
}
```

2. Add the Focused Value to your App
    

```swift
struct ExampleApp: App {

    @FocusedValue(\.print) // <--- New
    private var print

    var body: some Scene {
        DocumentGroup(newDocument: AppDocument()) { file in
            ContentView(document: file.$document)
        }
        .commands {
            CommandGroup(replacing: .printItem) {
                Button("Print...") {
                    print?() // <--- New
                }
                .keyboardShortcut("p", modifiers: [.command])
                .disabled(print == nil) // <--- If no Scene is active, print is disabled.
            }
        }
    }
}
```

3. Update your `ContentView` to print the document.
    

```swift
struct ContentView: View {

    @Binding
    var document: AppDocument

    var body: some View {
        TextEditor(text: $document.text)
            .focusedSceneValue(\.print) {
                print(document)
            }
    }
}
```

Try it out and you too can offer an incredible printing experience like [Lyrcs](https://lyrcs.app) ❤️
