Automation & Scripting

RSS for tag

Learn about scripting languages and automation frameworks available on the platform to automate repetitive tasks.

Automation & Scripting Documentation

Posts under Automation & Scripting subtopic

Post

Replies

Boosts

Views

Activity

applescript vs. keynote
hello, i'm having a strange problem with applescript+keynote. when i try to use system events to invoke menu commands via a script like click menu item "Copy Animation" of menu bar item "Format" of menu bar 1 (inside of enough tell...-brackets). the problem seems to boil down to the fact that (at least on my computer) the following script returns {} tell application "System Events" tell process "Keynote" return entire contents of menu bar 1 click menu item "Copy Animation" of menu bar item "Format" of menu bar 1 end tell end tell this script works for every app i've tried it for, but not keynote, where it always returns {} i see two possibilities: keynote is fundamentally broken in a way that its menu bar circumvents the canonical process to make a menu bar, or keynote is broken on my machine, in which case (i already reinstalled) i'm wondering what i can do to restore a good version. thanks for any help in advance peter purgathofer
3
0
63
2w
OSLog is not working when launching the app with Siri.
I am implementing AppIntent into my application as follows: // MARK: - SceneDelegate var window: UIWindow? private var observer: NSObjectProtocol? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } // Setup window window = UIWindow(windowScene: windowScene) let viewController = ViewController() window?.rootViewController = viewController window?.makeKeyAndVisible() setupUserDefaultsObserver() checkShortcutLaunch() } private func setupUserDefaultsObserver() { // use NotificationCenter to receive notifications. NotificationCenter.default.addObserver( forName: NSNotification.Name("ShortcutTriggered"), object: nil, queue: .main ) { notification in if let userInfo = notification.userInfo, let appName = userInfo["appName"] as? String { print("📱 Notification received - app is launched: \(appName)") } } } private func checkShortcutLaunch() { if let appName = UserDefaults.standard.string(forKey: "shortcutAppName") { print("🚀 App is opened from a Shortcut with the app name: \(appName)") } } func sceneDidDisconnect(_ scene: UIScene) { if let observer = observer { NotificationCenter.default.removeObserver(observer) } } } // MARK: - App Intent struct StartAppIntent: AppIntent { static var title: LocalizedStringResource = "Start App" static var description = IntentDescription("Launch the application with the command") static var openAppWhenRun: Bool = true @MainActor func perform() async throws -> some IntentResult { UserDefaults.standard.set("appName", forKey: "shortcutAppName") UserDefaults.standard.set(Date(), forKey: "shortcutTimestamp") return .result() } } // MARK: - App Shortcuts Provider struct AppShortcutsProvider: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: StartAppIntent(), phrases: [ "let start \(.applicationName)", ], shortTitle: "Start App", systemImageName: "play.circle.fill" ) } } the app works fine when starting with shortcut. but when starting with siri it seems like the log is not printed out, i tried adding a code that shows a dialog when receiving a notification from userdefault but it still shows the dialog, it seems like the problem here is when starting with siri there is a problem with printing the log. I tried sleep 0.5s in the perform function and the log was printed out normally try? await Task.sleep(nanoseconds: 500_000_000) // 0.5 seconds I have consulted some topics and they said that when using Siri, Intent is running completely separately and only returns the result to Siri, never entering the Main App. But when set openAppWhenRun to true, it must enter the main app, right? Is there any way to find the cause and completely fix this problem?
6
0
161
1w
AppIntent ignores registered dependencies when awaited
App intent has a perform method that is async and can throw an error, but I can't find a way to actually await the result and catch the error if needed. If I convert this working but non-waiting, non-catching code: Button("Go", intent: MyIntent()) to this (so I can control awaiting and error handling): Button("Go") { Task { do { try await MyIntent().perform() // 👈 } catch { print(error) } } } It crashes: AppDependency with key "foo" of type Bar.Type was not initialized prior to access. Dependency values can only be accessed inside of the intent perform flow and within types conforming to _SupportsAppDependencies unless the value of the dependency is manually set prior to access. Although it is invalid since the first version is working like a charm and dependencies are registered in the @main App init method and it is in the perform flow. So how can we await the result of the AppIntent and handle the errors if needed in the app? Should I re-invent the Dependency mechanism?
1
0
55
1w
Customizing section titles in the Shortcuts app (Favorites / Recents style)
Hi everyone, I’m currently experimenting with App Intents and I’m trying to customize the section titles that appear at the top of groups of intents inside the Shortcuts app UI. For example, in the Phone shortcut, there are built-in sections such as “Call Favorite Contacts” and “Call Recent Contacts” (see screenshot attached). Apple’s own system apps such as Phone, Notes, and FaceTime seem to have fully custom section headers inside Shortcuts with icon. My question is: 👉 Is there an API available that allows third-party apps to define these titles (or sections) programmatically? I went through the AppIntents and Shortcuts documentation but couldn’t find anything. From what I can tell, this might be private / Apple-only behavior, but I’d be happy to know if anybody has found a supported solution or a recommended alternative. Has anyone dealt with this before? Thanks! Mickaël 🇫🇷
2
0
124
1w
SetFocusFilterIntent app cannot be copied to another Mac
I have recently added a SetFocusFilterIntent target extension to my app which is a system utility which goes into the menu bar(Application is agent = YES). I have followed the approach in the WWDC22 video introducing Focus Intent and I have created an App Groups to being able to make the Extension to communicate with my main app, however from when I did this sometimes when I run the app I do get this log line: Couldn't read values in CFPrefsPlistSource<0x97cd34700> (Domain: group.xxx.xxx.MyApp, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd Despite this the Focus mode integration is working correctly on my development Mac. However I used to Archive the app and then Copy the app to my MacBook but when I do that now my other Mac cannot open the app and it is giving me an error. If I revert this change then I can bring the app back to my other Mac as usual following the procedure: Product -> Archive. Then from the archiver: Distribute App -> Copy App. After that I copy the app generated to the App folder of my other MacBook but it doesn't open anymore. During the archival phase now I am even getting this warning: MyAppFocus.appex is an ExtensionKit extension and must be embedded in the parent app bundle's Extensions directory, but is embedded in the parent app bundle's ../../../BuildProductsPath/Release/MyApp.app/Contents/Extensions directory. How can I solve this issue? If I rollback the commit related to this SetFocusFilterIntent new feature the app can be Copied and moved to the other Mac as before. Is this related to the extension or to the fact that I had to use this new entitlement: com.apple.security.application-groups ?
0
0
32
6d
Cannot make my app appear in “Share with App” action in Shortcuts – How to allow receiving images from Shortcuts?
Hi, I’m trying to integrate my iOS app with Shortcuts. My goal is: In the Shortcuts app → Create a shortcut → Select an image → Share the image directly to my app for analysis. However, when I try to add the “Share with App” / “Open in App” / “Send to App” action in Shortcuts: My app does NOT appear in the list of available apps. I want my app to be selectable so that Shortcuts can send an image (UIImage / file) to my app. What I have tried My app supports receiving images using UIActivityViewController and Share Extension. I created an App Intents extension (AppIntent + @Parameter(file)...) but the app still does not appear in Shortcuts “Share with App”. I also checked the Info.plist but didn’t find any permission related to Shortcuts. The app is installed on the device and works normally. My question What permission, Info.plist entry, or capability is required so that my app becomes visible in the Shortcuts app as a target for image sharing? More specifically: Which extension type should be used for receiving images from Shortcuts? App Intents Extension? Share Extension? Intent Extension? Do I need a specific NSExtensionPointIdentifier for Shortcuts integration? Do I need to declare a custom Uniform Type Identifier (UTI) or add supported content types so Shortcuts knows my app can handle images? Are there any required entitlements / capabilities to make the app appear inside the “Share with App” action? Goal Summary I simply want: Shortcuts → Pick Image → Send to My App → App receives the image and processes it. But currently my app cannot be selected in Shortcuts. Thanks in advance for any guidance!
2
0
112
5d
Custom AppEntity nested dictionary
I am creating an AppIntent to be used with Shortcuts and I would like to return a flexible dictionary of values with nested structures. As far as I understand the custom AppEntity only uses the displayRepresentation to store a title and subtitle which are LocalizedStringResource. types. Although I can convert my dictionary into a string I found no way in shortcuts to be able to retrieve the original structure of it and inspect individual elements like in subsequent actions. Is there a way to do this? Thank you in advance Nick Karanatsios
0
0
74
4d
App 自动更新,导致App功能错乱。
当用户开启App自动更新后,自动更新App后,App有些功能会错乱。 1.有的会触发旧App代码功能,如旧版本有个选择框,在新版本选择框从界面移除了,但自动更新看,有的用户会还会触旧版本选择框的功能 2.数据错乱,如App录入数字6,发送到服务端变成5.4 现在发现这些问题。都是要把App删除,重新下载就可以。 请问要如何避免这样的问题。 App是有Objective-C,会不会与开启 BITCODE有关?
0
0
63
2d