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

Best Practice for Confirming Siri Shortcuts Availability Before Prompting User Interaction
I'm developing an iOS app that uses Siri Shortcuts to enhance the user experience. Currently, I have implemented functionality that allows users to perform certain actions via Siri Shortcuts. My team wants to improve the user experience by giving an instructional audio prompt (e.g., "say 'hey Siri [action name]' if you want to [perform action]") to users. However, we want to ensure this prompt is only played when the user has already enabled Siri Shortcuts. The challenge is determining whether Siri Shortcuts are properly enabled before suggesting their use. We want to avoid situations where users follow our audio instructions to use Siri, only to discover that Siri Shortcuts aren't properly configured on their device. Since we're using Siri Shortcuts for this feature, the standard requestSiriAuthorization(_:) method doesn't apply to our use case(It said You don’t need to request authorization if your app only supports actions in the Shortcuts app. in https://developer.apple.com/documentation/sirikit/requesting-authorization-to-use-siri). What is the recommended approach to verify that Siri Shortcuts are properly enabled before prompting users to interact with them? Is there a reliable way to check this status(should be the bool value of the toggle in the pic below) programmatically? Thank you for your assistance.
1
0
26
1d
How to create an intent that Apple Maps knows about?
I asked a question similar to this earlier, but I think this is probably the better question. I have a food-ordering app. When the user wants to pick up food, I'd like for Apple Maps to automatically display the location of the restaurant that the user is driving to. Calendar does something similar. If there is an event that is soon, the location in the calendar-event shows up in Apple Maps. I'd like to do the same thing. So, when the user makes an order, they'll need to drive to the location fairly quickly. So, I'd like to launch Apple Maps, see the location of the restaurant where I'm picking up food, and then get directions to it. Bonus points if this also works when I have CarPlay.
0
0
39
1w
osascript System Events Failed to list Processes That Have The Same Name
I ran the following script while both VSCode and Windsurf were open. tell application "System Events" set electronProcesses to every application process whose name is "Electron" set outputText to "" repeat with p in electronProcesses set outputText to outputText & "Process: " & name of p set outputText to outputText & ", Displayed name: " & displayed name of p set outputText to outputText & ", Frontmost: " & frontmost of p & " " end repeat return outputText end tell The script incorrectly returned two Electron processes, where both were showing Windsurf as the displayed name. The output of the above script is: Process: Electron, Displayed name: Windsurf, Frontmost: false Process: Electron, Displayed name: Windsurf, Frontmost: false Separately, both Windsurf and VSCode share the same process name (Electron) but have different displayed names. This issue appears to affect how the frontmost application is detected, when using the following script: set frontApp to first application process whose frontmost is true The frontApp is incorrectly returned when switching between VSCode and Windsurf.
3
0
73
3w
Shortcuts: Invalid action metadata
I have a habit tracker app that uses App Intents and Shortcuts. The app uses SwiftData to persist data, just in case that's important. One of the shortcuts serves to log habits. However, when the app has been in the background for a good while (over an hour or so), that particular shortcut always fails when I try to run it in the Shortcuts app with the system error "Invalid action metadata" caused by "a bug in the host app". The app has a total of 9 shortcuts, and it's just this one particular shortcut that seems to be failing – the others continue to run without any issues even after the app has been in the background for a long time. The app intent/shortcut that is problematic is the one called HabitEntryAppIntent. For example purposes, I've also included one of the non-problematic intents in the code snippet below called HabitEntryCounterForTodayAppIntent. Both of these intents have one @Parameter value of type HabitEntity. I'll post code snippets in the replies because the character limit is not large enough to include them here, or view them in this GitHub gist: Code snippets on GitHub I've tried everything I can think of whilst debugging, but none of the following fixed the error: Removed all usage of @MainActor and mainContext by replacing the ModelContext used in perform() with a locally created property. Removed all usage of static shared properties like Calendar.shared and ModelContainer.shared and replaced them with local properties. Removed all non-essential code such as the code for context.undoManager and WidgetManager.shared.reload(.all) and really striped it all down to the absolute essentials. Reduced the number of shortcut phrases in the problematic shortcut because there was perhaps too many (>10) originally. You might have noticed that the perform() method in the problematic intent manipulates the database whilst the non-problematic intent only reads the database. Given that the two intents in the snippet above both have the same @Property(...) var habitEntity: HabitEntity values, I tried to swap the contents of the perform() methods over to see what would happen. And here's what's strange: When the perform() method from the problematic HabitEntryAppIntent is used in HabitEntryCounterForTodayAppIntent, it works without any issues and successfully logs habits! And then when the perform() method from the non-problematic HabitEntryCounterForTodayAppIntent is used in HabitEntryAppIntent it fails with the system error "Invalid action metadata". This suggests that the problem is not in the code that logs the habit entries but rather something is wrong with HabitEntryAppIntent itself. I also tried changing the metadata used in HabitEntryAppIntent and its shortcut. I copied all the metadata used in HabitEntryCounterForTodayAppIntent (the title, description, parameterSummary etc) and pasted it into HabitEntryAppIntent. And did the same with the metadata in the shortcut (phrases, shortTitle etc) so that all the metadata used in HabitEntryAppIntent matched that used in HabitEntryCounterForTodayAppIntent. However, the shortcut for HabitEntryAppIntent continued to fail. Thus, it doesn't seem to be an issue with the code in perform() because that code succeeds when used in another app intent. And, despite the "metadata" error message, it doesn't seem to be an issue with the metadata in the app intent because I've tried using metadata from the non-problematic intent but it still fails. I have watched all WWDC videos related to app intents and shortcuts, and looked through the developer forum for similar questions, but I'm completely stumped by this issue and why it's only affecting one of my shortcuts. Also worth mentioning is that the widgets in the app that log habits using the same app intent do not suffer the same issue; they continue to work even after the Shortcut has failed. Moreover, if I try running the problematic shortcut for HabitEntryAppIntent and see the system error message, then run the shortcut for HabitEntryCounterForTodayAppIntent (which always succeeds), and then try running the HabitEntryAppIntent shortcut again, it then runs successfully on the second attempt. It seems that running HabitEntryCounterForTodayAppIntent fixes the issue, at least temporarily.
2
0
72
3w
AppleScript access to "Show on all Spaces" Wallpaper setting
I am creating scripts to automatically switch the wallpapers on my multiple displays. System Events exposes almost all of the options accessible in the Wallpapers pane of system settings, but not the option to "Show on all Spaces". I want to add that option to the following script: tell application "System Events" set intervalSeconds to 900.0 set wpDir to POSIX file "/Path/to/Folder/" set picture rotation of every desktop to 1 set random order of every desktop to true set pictures folder of every desktop to wpDir set change interval of every desktop to intervalSeconds do shell script ("killall Dock") end tell Also, the foregoing script does not seem to successfully set the interval value, although it does not throw an error. Not sure why that does not work. Any thoughts or insights would be welcome. Thank you
0
0
43
3w
Does INIntent no longer work on macOS? Can't get shortcut to show up in Shortcuts app
Was going to add a shortcut to an app via INIntent. I followed the WWDC developer.apple.com/videos/play/wwdc2021/10232/?time=986 Steps: Created a .intentdefinition file and created an intent. Added the intent to .intentdefinition and compiled the app. Import the header file for the custom intent in the AppDelegate MyIntentname.h Have the AppDelegate conform to the protocol created in the generated code. Implement: -application:handlerForIntent: and return self (the app delegate) Run the app. Open the Shortcuts app and search for the 'shortcut' (according to the WWDC video linked above it should show up in the actions list). Doesn't show up in the list. I tried moving the build application out from Debug to my Applications folder to see if that would help the Shortcuts app find it, but it didn't. Am I missing a step/doing something wrong?
2
0
48
3w
terminal fulldisk access fails for tmutil latestbackup
I am on MacOS 15.5 trying to access tmutil latestbackup in AppleScript: set latestBackup to do shell script "tmutil latestbackup" It works perfect when run from script editor, and script editor is in full disk access permission list. When I export to an app and run it it fails with: Error retrieving latest backup: tmutil: latestbackup requires Full Disk Access privileges. To allow this operation, select Full Disk Access in the Privacy tab of the Security & Privacy preference pane, and add Terminal to the list of applications which are allowed Full Disk Access. Error code: 80 Terminal is on list, as is name of the app. I have same issue running in safe mode. I have tried deleting and redefining full disk access entries, all to no avail. Apple tech support says its a developer issue, but code works in script editor. any ideas?
2
0
69
4w
LocalDictionary spelling adding words
Sorry if topic is not exact. I write Ainu in various Roman Latin scripts on English GUI Catalina ,Text Edit. The Ainu words are similar to English ex. 'an' in Ainu is 'exist' ,Ainu Language exists 'Ne Ainu itak an ',so spell checker will not red dot many words also some Ainu words look like other foreign words. I open LocalDictionary and find it blank ,so I open TextEdit and open show spelling grammar 100 words out of 200 are red dotted !the others are not learned, so I press' learn' and it skips to some words not Allan after 100 it stops ,then I go to LocalDictionary and see all those words alphabetical order ,! great ! but what about the rest ? why does select half of the words and /part/ of a phrase/ 'Itak a-e-yay-/han-nok-kar-a' = to study language by oneself.
0
0
46
May ’25
Siri Intent - Car Commands
Hi Community, I'm new on Siri intents and I'm trying to introduce into my App a Siri Intent for Car Commands. The objective is to list into the Apple Maps the Car list of my App. Currently I've created my own target with its corresponding IntentHandlings, but in the .intentdefinition file of my App, I'm not able to find the List Car Intent. https://developer.apple.com/documentation/sirikit/car-commands Do I need some auth? Also I share my info.plist from the IntentExtension. Thank you very much, David.
0
0
35
May ’25
Keynote broken video links after macOS 15.4.1 update
After updating to macOS 14.4.1 keynote can't find all the outside video links. I have over 15 keynote presentations that I use to show videos. I have over 1500 videos. If I manually replace each video, I lose all the settings (thumbnails, cropping, animations, etc.). That's 15 years of work lost! Apple engineers tell me there's no other solution but to replace the videos manually. I've tried creating scripts via AIs but none of them work. Does anyone have any ideas?
2
0
39
May ’25
AppIntent AppShortcuts How to get a Double returned for a parameter and how to use the resolvers?
Hello, I have two related questions: in this AppIntent: https://github.com/poml88/FLwatch/blob/moresimple/SharedPhoneWatch/AppIntents/AddInsulin.swift#L2 i am trying to work with are returned Double as the parameter. But it does not fully work, because there is a locale issue. in some languages the decimal point is a comme. If that is so, Siri returns 3,5 but the system does not use it as a double. How to solve that? or, she is returning five, not 5 and again. The system does not recognise the double. It seems Apple has some resolvers for this, for example: DoubleFromStringResolver. https://developer.apple.com/documentation/appintents/resolvers But I cannot figure out how to use them are how to call that resolver. Can somebody help, please? Thanks.
1
0
77
May ’25
Shortcuts Services doesn't work properly in Books & iMessages
The built-in Books and iMessages on the latest macOS can not handle Shortcuts properly. If Books (no matter the Home scheme or the reading scheme) or iMessages is the current focused application, Shortcuts doesn't work. Once I move out and focus app turns to Finder or any other app, Shortcuts works properly. An exception is that when I pin the shortcut in the Menu Bar, the Menu Bar one works, while the one in the application's menu doesn't work. I have no idea why this would happen. Could it be part of privilege control or something?
0
1
22
May ’25
Disambiguation for .system.search AppIntent
I'd like to display a list of items to disambiguate for a fulltext search intent. Using the Apple AppIntentsSampleApp, I added TrailSearch.swift: import AppIntents @AssistantIntent(schema: .system.search) struct TrailSearch: AppIntent { static let title: LocalizedStringResource = "Search Trail" static let description = IntentDescription("Search trail by name.", categoryName: "Discover", resultValueName: "Trail") @Parameter(title: "Trail") var criteria: StringSearchCriteria func perform() async throws -> some IntentResult & ReturnsValue<TrailEntity> { if criteria.term.isEmpty { throw $criteria.needsValueError(IntentDialog("need value")) } let trails = TrailDataManager.shared.trails { trail in trail.name.contains(criteria.term) } if trails.count > 1 { throw $criteria.needsDisambiguationError(among: trails.map { StringSearchCriteria(term: $0.name) }) } else if let firstTrail = trails.first { return .result(value: TrailEntity(trail: firstTrail)) } throw $criteria.needsValueError(IntentDialog("Nothing found")) } } Now when I type "trail" which matches several trails and thus lets us enter the disambiguation code path, the Shortcut app just displays the dialog title but no disambiguation items to pick from. Is this by design or a bug? (filed as FB17412220)
0
0
23
Apr ’25
Parameter recognition on AppShortcuts invocation not consistent
While playing around with AppShortcuts I've been encountering some problems around getting the invocation phrase detected and/or the parameter get recognized after invocation phrase via Siri. I've found some solutions or explanations here in other posts (Siri not recognizing the parameter in the phrase & Inform iOS about AppShortcutsProvider), but I still have one issue and it's about consistency. For context, I've defined the parameter to be an AppEntity with it's respective query conforming to the EntityStringQuery Protocol in order to be able to fetch entities with the string given by Siri struct AnIntent: AppIntent { // other parts hidden for clarity @Parameter var entity: ModelEntity } For an invocation phrase akin to "Do something with in ", if the user uses the phrase with a entity previously donated via suggestedEntities() the AppShortcut get executed without problems. If the user uses a phrase with no parameter, like "do something with ", if the user gets asked to input the missing parameter and inputs one, it may or may not get recognized and be asked to input a parameter again, like in a loop. This happens even if the parameter given is one that was donated. I've found that when this happens the entities(matching string: String) function in the EntityQuery doesn't get called. The input can be of one word or sometimes two and it will not be called. So in other words entities(matching string: String) does not get called on every user parameter input Is this behavior correct? Do parameters have some restrictions on length or anything? Does Siri shows the user suggested entities when asked for entity input? It doesn't on my end. Additional question related to AppShortcuts: On AppShortcut definition, where the summary inside the parameter presentation is used? I see that it was defined in the AppIntentsSampleApp for the GetTrailInfo Intent but didn't find where it was used
0
0
29
Apr ’25
Proper way to create an AppleEvent record descriptor from NSDictionary
When using NSScriptCommand, is there any way to create an NSAppleEventDescriptor from an NSDictionary with arbitrary keys without using keyASUserRecordFields? Am I correct in thinking that this constant is deprecated? I ask because there is still active documentation using it. Is there another way to return a record where the keys aren't known at compile-time?
0
0
36
Apr ’25
Cannot instantiate VIP object/property out of mail app
Is VIP an object contained in the mail or contacts apps/objects? Or is it just a property somewhere? Or is it an independent object? Where is the VIP object? Is it still managed in the mail app or is it just hidden because the design is changing at Apple? The following AppleScript is failing: tell application "Mail" set theVIPs to VIPs with the error: error "Die Variable „VIPs“ ist nicht definiert." number -2753 from "VIPs" (The variable "VIPs" is not defined.". In Mail.sdef documentation and in Contacts.sdef documentation I cannot find any documentation of VIP object or VIP property.
7
0
56
Apr ’25
What is the correct syntax to continue in app for custom intent?
I have a custom intent. When my app is unable to complete the resolution of a parameter within the app extension, I need to be able to continue within the app. I am unable to figure out what the correct objective C syntax is to enable the execution to continue with the app. Here is what I have tried: completion([[PickWoodIntentResponse init] initWithCode:PickWoodIntentResponseCodeContinueInApp userActivity:nil]); This results in the following error: Implicit conversion from enumeration type 'enum PickWoodIntentResponseCode' to different enumeration type 'INAnswerCallIntentResponseCode' (aka 'enum INAnswerCallIntentResponseCode') I have no idea why it is referring to the enum type of 'INAnswerCallIntentResponseCode' which is unrelated to my app. I have also tried: PickWoodIntentResponse *response = [[PickWoodIntentResponse init] initWithCode:PickWoodIntentResponseCodeContinueInApp userActivity:nil]; completion(response); but that results in 2 errors: Implicit conversion from enumeration type 'enum PickWoodIntentResponseCode' to different enumeration type 'INAnswerCallIntentResponseCode' (aka 'enum INAnswerCallIntentResponseCode') and Incompatible pointer types passing 'PickWoodIntentResponse *' to parameter of type 'INStringResolutionResult *' The relevant autogenerated code provided to me with the creation of my intent is as follows: @class PickWoodIntentResponse; @protocol PickWoodIntentHandling <NSObject> - (void)resolveVarietyForPickWood:(PickWoodIntent *)intent withCompletion:(void (^)(INStringResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveVariety(for:with:)) API_AVAILABLE(ios(13.0), macos(11.0), watchos(6.0)); @end typedef NS_ENUM(NSInteger, PickWoodIntentResponseCode) { PickWoodIntentResponseCodeUnspecified = 0, PickWoodIntentResponseCodeReady, PickWoodIntentResponseCodeContinueInApp, PickWoodIntentResponseCodeInProgress, PickWoodIntentResponseCodeSuccess, PickWoodIntentResponseCodeFailure, PickWoodIntentResponseCodeFailureRequiringAppLaunch } @interface PickWoodIntentResponse : INIntentResponse - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithCode:(PickWoodIntentResponseCode)code userActivity:(nullable NSUserActivity *)userActivity NS_DESIGNATED_INITIALIZER; @property (readonly, NS_NONATOMIC_IOSONLY) PickWoodIntentResponseCode code; @end Am I overlooking something? What would be the proper syntax to have within the completion block to satisfy the compiler?
1
0
47
Apr ’25
Import Files into Photos script failed
I am trying to setup in Automator a Folder Action, where screenshots on Desktop are automatically imported into my Photos app Unfortunately, the automation is not working. When I have a screenshot on the Desktop and I open Automator to manually trigger, I receive the error: The action "Import Files into Photos" encountered an error: "Import Files into Photos script failed" Under log, it further says: The action "Import Files into Photos" was not supplied with the required data
6
0
42
Apr ’25
/usr/bin/shortcuts no longer works in 14.7.5 (23H527) ?
I've been using /usr/bin/shortcuts for various tasks (eg. Quicksilver uses it to list and run shortcuts), and after updating from 14.7.4 to 14.7.5 the tool gets killed on startup. Eg. here is what it looks like in my shell: ❯ shortcuts list zsh: killed shortcuts list (And this is regardless of whether I have "full disk access" or "developer tools" toggled on or off for iTerm.) Looking at system logs it seems like the binary is missing an entitlement, which causes MACF / Gatekeeper to throw a fit: 2025-04-12 18:38:48.847576 kernel: mac_vnode_check_signature: /usr/bin/shortcuts: code signature validation failed fatally: When validating /usr/bin/shortcuts: in-kernel: com.apple.shortcuts.ShortcutsCommandLine disallowed without com.apple.private.security.restricted-application-groups 2025-04-12 18:38:48.847582 kernel: validation of code signature failed through MACF policy: 1 2025-04-12 18:38:48.847583 kernel: check_signature[pid: 2475]: error = 1 2025-04-12 18:38:48.847587 kernel: proc 95761: load code signature error 4 for file "shortcuts" 2025-04-12 18:38:48.847613 kernel: exec_mach_imgact: not running binary "shortcuts" built against preview arm64e ABI 2025-04-12 18:38:48.855481 syspolicyd: (Security) SecTrustEvaluateIfNecessary 2025-04-12 18:38:48.857970 syspolicyd: [com.apple.syspolicy.exec:default] GK evaluateScanResult: 2, PST: (path: /usr/bin/shortcuts), (team: (null)), (id: (null)), (bundle_id: (null)), 0, 0, 1, 0, 1, 1, 0evaluateScanResult: 2, PST: (path: /usr/bin/shortcuts), (team: (null)), (id: (null)), (bundle_id: (null)), 0, 0, 1, 0, 1, 1, 0 I used Time Machine to compare the binary's entitlements between 14.7.4 and 14.7.5, and looks like in 14.7.5 /usr/bin/shortcuts indeed is missing the com.apple.private.security.restricted-application-groups entitlement that 14.7.4 had. The old binary had these two entitlements that the new one doesn't: [Key] com.apple.private.security.restricted-application-groups [Value] [Array] [String] group.com.apple.shortcuts [String] group.is.workflow.my.app [String] group.is.workflow.shortcuts [Key] com.apple.security.application-groups [Value] [Array] [String] group.com.apple.shortcuts [String] group.is.workflow.my.app [String] group.is.workflow.shortcuts Is there a sensible workaround for this (and by "sensible" I mean something that'd allow me to keep using the tool)? (I already asked this on the support forums but I figured I might as well ask here too)
2
0
75
Apr ’25