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

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
64
1d
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
102
2d
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
25
2d
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
109
3d
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
37
3d
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
152
1w
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
53
1w
oascript stop working for sending notification
I have a script that stop working since Tahoe migration. The script need to send a notification on the my mac. The issue is this line: osascript -e 'display notification "The task has been completed" with title "✅ My script"' It doesn't fail (return 0), nothing in outputs, but doesn't show anything. I check all my notification settings, but all seems to be right, I tested the configuration of iterm & script editor. And the global ettongs of the notifications:
0
0
49
2w
Siri media search unable to provide keyword
Hi, I am developing a music app. We are using siri media search functionality for a while. We recently had a case where siri would not provide keyword for a search. When user speaks "Play Kid songs" (in Turkish, çocuk şarkıları çal), when I debug I see mediaSearch.mediaName is nil. When user speaks "Play Kids" (in Turkish, çocuklar çal) a keyword is given and we can search and play related song. Normally I would think that siri is somehow censoring the word "Kid". But when i try the same voice search in Spotify, I get a children song search result. I've read documentations and searched web but couldnt find any similar experience. What would be the cause, is there an extra setting for this kind of behaviour. What would be the cause or a different capability that Spotify can get a keyword out of this voice search but not us?
0
0
37
2w
AppleScript scripts return -600 error in STP 231 for Tahoe
The AppleScript script below returns a -600 error (application not running) under STP Tahoe version 231 and macOS 26.1. It functioned flawlessly under previous STP versions under macOS 15.x and 14.x. tell application "Safari Technology Preview" tell front window set _old_tab to current tab set _new_tab to make new tab at after _old_tab set current tab to _new_tab end tell end tell The following version returns a syntax error. Tell application "System Events" Tell process "Safari Technology Preview" tell front window set _old_tab to current tab set _new_tab to make new tab at after _old_tab set current tab to _new_tab end tell end tell end tell How would these scripts need to be fixed for STP 231 for Tahoe?
2
0
138
2w
Activating application from Terminal occasionally fails on macOS 26
On macOS Tahoe 26 activating GUI apps from command-line often fails. It launches the app but not brings to the foreground as expected. For example, running the following commands in Terminal is expected to launch Pages and bring it to the foreground. open /Applications/Pages.app or osascript -e `tell application "Pages" to activate` Moreover, they sometimes not return in Terminal. These commands worked as expected until macOS 15 but no more in macOS 26. The tricky part is that this failure doesn't happen 100% of the time; it occurs randomly. However, since multiple users of my app have reported the same symptoms, and I can reproduce it not only with my app but also with apps bundled to macOS, I don't believe this is an issue specific to my environment alone. I’ve already filed this issue: FB21087054 Open version: https://github.com/1024jp/AppleFeedback/issues/87 However, I’d like to know if any workaround exists or my understanding is wrong, especially for case with osascript.
3
1
111
3w
Shortcut to Send Address to Tesla Navigation
Hi, new to this forum. Recently discovered how to share a location in Maps app with my Tesla to automatically start navigating. How cool is that! Being the nerd that I am, I wrote a shortcut to select a contact and share it's address with my Tesla. That way, I don't leave the Maps app in memory to use up my battery, and don't have to go to all the trouble of swiping Maps out of memory. JK. Anyway, when I share the shortcut-selected address with the Tesla, it says "Error this content could not be shared". To me this means the address as shared by the shortcut is not in the same format as when you share it directly from Maps. So the question is, how can I send a properly formatted location from my shortcut? Thanks...
1
1
1.7k
3w
Press return
Here is the appleScript part of my script: tell application "Finder" activate open application file "Messages.app" of folder "Applications" of folder "System" of startup disk end tell What I need is a step to send the message already inside the Mesage.app. The message is ready to send. I just would like a step that will act as "Return" to send the message. Again I have already prepared message to send but just need a step to send the message. Is there a possible step to perform the" Return" command to iMessage?
1
0
65
3w
Visual Intelligence: App Intent Not Found?
I'm making a PoC for Visual Intelligence integration in iOS. It's a very simple setup... the extension will always reply with a couple of static "results" just so I can verify that it's working and figure out how to handle receiving app activation from the Intents framework. The app seems to be registering the VI intent correctly, because I see my app's name in the tab list of providers for search results, but when I select my app, I always get no results. I looked at the console for the moment I'm selecting my app and seeing this error: error 16:37:09.433057-0600 duetexpertd [com.hairlessape.VisualIntelligenceProvider.VIAppIntent] Unable to get connection interface: Error Domain=LNConnectionErrorDomain Code=1100 "Unable to locate `com.hairlessape.VisualIntelligenceProvider.VIAppIntent` for the `com.apple.appintents-extension` extension point" No amount of web searching or AI interrogation has produced any headwind here. I've checked the build product and I can see the VIAppIntent.appex file in the Extensions\ folder of my app bundle. I've triple checked the bundle identifiers, code file membership, installed the app from an IPA, restarted my phone, etc. I cannot get my intent to be queried and it's very frustrating. I've put the PoC project on Github: https://github.com/JoshuaSullivan/VisualSearchForVI
5
0
122
4w
AppShortcutsProvider triggered for unsupported OS
Hi! I have an AppShortcutsProvider that has been marked @available(iOS 17.0, *), because all Intents used within it are only available in iOS 17. So the static var appShortcuts should only be accessible in iOS 17, obviously. Now this code has been released and works fine for iOS 17 users. But I just noticed that around 150 iOS 16 users have crashed in the static var appShortcuts, or more specifically, the defaultQuery of one of the Intents. This should not be possible, as neither the AppShortcutsProvider, nor the Intent is exposed to iOS 16, they are marked as @available(iOS 17.0, *). Any idea why this could happen? Here is the crash log: Crashed: com.apple.root.user-initiated-qos.cooperative 0 libswiftCore.dylib 0x3e178c swift::ResolveAsSymbolicReference::operator()(swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*) 1 libswiftCore.dylib 0x40bec4 swift::Demangle::__runtime::Demangler::demangleSymbolicReference(unsigned char) 2 libswiftCore.dylib 0x408254 swift::Demangle::__runtime::Demangler::demangleType(__swift::__runtime::llvm::StringRef, std::__1::function<swift::Demangle::__runtime::Node* (swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*)>) 3 libswiftCore.dylib 0x3e9680 swift_getTypeByMangledNameImpl(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) 4 libswiftCore.dylib 0x3e4d9c swift_getTypeByMangledName 5 libswiftCore.dylib 0x3e50ac swift_getTypeByMangledNameInContext 6 MyApp 0x3f6b8c __swift_instantiateConcreteTypeFromMangledName (<compiler-generated>) 7 MyApp 0x640e3c one-time initialization function for defaultQuery + 146 (IntentAction.swift:146) 8 libdispatch.dylib 0x3eac _dispatch_client_callout 9 libdispatch.dylib 0x56ec _dispatch_once_callout 10 MyApp 0x64109c protocol witness for static AppEntity.defaultQuery.getter in conformance IntentAction + 124 (IntentAction.swift:124) 11 AppIntents 0x15c760 _swift_stdlib_malloc_size 12 AppIntents 0x19dfd4 __swift_destroy_boxed_opaque_existential_1Tm 13 MyApp 0x52dadc specialized ActionIntent.init(action:) + 41 (ActionIntent.swift:41) 14 MyApp 0x52df80 specialized static MyShortcuts.appShortcuts.getter + 17 (MyShortcuts.swift:17)
4
1
1.1k
4w
AppShortcutsProvider limitedAvailability in result builder crash
My team is preparing for iOS 18, and wanted to add intents using assistant schemas that are iOS 18 and above restricted. We noticed that the result builder for AppShortcuts added support for limitedAvailabilityCondition from iOS 17.4 so we marked the whole struct as available from it. The app compiles but writing a check like below inside appShortcuts property a crash will happen in iOS 17.5 runtime. (Removing the #available) is solving this problem. if #available(iOS 18, *) { AppShortcut( intent: SearchDonut(), phrases: [ "Search for a donut in \(.applicationName)" ], shortTitle: "search", systemImageName: "magnifyingglass" ) } We tried out putting the os check above and returning shortcuts in arrays and that both compiles and runs but then AppShortcuts.strings sends warnings that the phrases are not used (This phrase is not used in any App Shortcut or as a Negative Phrase.) because the script that extracts the phrases somehow fails to perform when shortcuts are written like below: static var appShortcuts: [AppShortcut] { if #available(iOS 18.0, *) { return [ AppShortcut( intent: CreateDonutIntent(), phrases: [ "Create Donut in \(.applicationName)", ], shortTitle: "Create Donut", systemImageName: "pencil" ) ] } else { return [ AppShortcut( intent: CreateDonutIntent(), phrases: [ "Create Donut in \(.applicationName)", ], shortTitle: "Create Donut", systemImageName: "pencil" ) ] } } This is very problematic because we can't test out on TF with external users new intents dedicated for iOS 18. We filed a radar under FB15010828
2
5
611
4w
UI Testing and 'Allow Paste'
I am developing an app that allows the user to ask it to process the clipboard contents and do something with it. In developing a XC UI Test, I find the app stops while it waits for the user to give permission. That breaks the automation. I tried: let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") let allowButton = springboard.buttons["Allow Paste"] But that does not work. Is there a way to tell the framework to automatically give the test permission to access the Paste clipboard (or to allow me to write tests to grant this)?
0
0
57
Nov ’25
AppleScript
Here's my AppleScript: tell application "Finder" activate open application file "Messages.app" of folder "Applications" of folder "System" of startup disk end tell I just need the step to send the message making the script automatically send the message which has already been created. This step opens the completed iMessage ready to send . I want to send it without and keyboard usage. All that is needed is the step to send
0
0
39
Nov ’25