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

Trouble implementing search via Siri
Hi, we're having trouble implementing search through Siri voice commands. We already did it successfully for audio playback using INPlayMediaIntentHandling. For search, none of the available ways works. Both INSearchForMediaIntentHandling and ShowInAppSearchResultsIntent never open the App in the first place. We tried various commands, but e.g. "Search for " sometimes opens the Apple Music app and sometimes shows a Google search widget. Our app is never taken into consideration for providing any results. We implemented all steps mentioned in WWDC videos and documentation (e.g. https://developer.apple.com/documentation/appintents/making-in-app-search-actions-available-to-siri-and-apple-intelligence), but nothing seems to work. We're mainly testing on iOS 18 currently. Any idea why this is not working?
0
0
46
Jul ’25
Issue syntax “AND” conditions to trigger automation
I’m looking into activating my gate (has a dedicated app to it) while getting near home. i thought that a combination of Car bluetooth connection/Carplay connection as well as a 50 meter radius from home location would be nice to trigger the gate app. However, I find it hard to set these 2 parallel conditions in Shortcuts. I managed to set connection to car’s Bluetooth, but next screen would suggest the “do” action rather than offer additional conditions. i couldn‘t handle the “if” option. would like some help.
0
0
98
Jul ’25
App Intents not working with Siri
This implementation works very well for spotlight and App Shortcuts, but for voice commands by Siri, they don't work. AppShortcutsProvider import AppIntents struct CustomerAppIntentProvider: AppShortcutsProvider { @AppShortcutsBuilder static var appShortcuts: [AppShortcut] { AppShortcut( intent: StoresAppIntent(), phrases: ["Mostre as lojas do (.applicationName)"], shortTitle: LocalizedStringResource("Lojas"), systemImageName: "storefront" ) } } Ex. do AppIntent import AppIntents import Foundation import Loyalty import ResourceKit struct StoresAppIntent: AppIntent { static var title: LocalizedStringResource = "Mostrar as lojas" static var description: IntentDescription? = "Este atalho mostra as lojas disponiveis no app" static var openAppWhenRun: Bool = true static var isDiscoverable: Bool = true @MainActor func perform() async throws -> some IntentResult { if let url = URL(string: “app://path") { UIApplication.shared.open(url, options: [:], completionHandler: { (success) in if success { print("Opened \(url)") } else { print("Failed to open \(url)") } }) } return .result() } } Basically that's what I did Our apps are with a minimum target of iOS 17 and I tested it on an iPhone 11 with Portuguese language and Siri in Portuguese
1
0
113
Jul ’25
AppIntent take a photo?
Hi i'm new to swift/swiftui i want to my app shortcut to have the ability to take a photo within my AppIntent instead of having to configure a 'Take a photo' action in the Shortcuts app and then parsing that to my Appintent (for less human error). Is this possible? I read there's a protocol called CameraCaptureIntent but i think it's only used for a separate extension like for Control Center, Lock Screen, and Action buttons :(
0
0
56
Jul ’25
AppIntents EntityPropertyQuery, how does "Filter Entity where" work?
When you correctly implement EntityPropertyQuery on an AppEntity, Shortcuts will expose a "Find Entity" action that calls into entities(matching:mode:sortedBy:limit:). This is demoed in the "Dive into App Intents" session and works as expected. However, with this action, you can change the "All Entity" input to a list variable which changes the action text from "Find All Entity" to "Filter Entity where" still giving you the same filter, sort and limit options. This appears to work as expected too. But, what's unexpected is that this filter action does not appear to call any method on my AppEntity code. It doesn't call entities(matching:mode:sortedBy:limit:). One would think there would need to be a filter(entities:matching:mode:sortedBy:limit:) to implement this functionality. But Shortcut just seems to do it all on it's own. I'm mostly wondering, how is this even working? Here's some example code: import AppIntents let books = [ BookEntity(id: 0, title: "A Family Affair"), BookEntity(id: 1, title: "Atlas of the Heart"), BookEntity(id: 2, title: "Atomic Habits"), BookEntity(id: 3, title: "Memphis"), BookEntity(id: 4, title: "Run Rose Run"), BookEntity(id: 5, title: "The Maid"), BookEntity(id: 6, title: "The Match"), BookEntity(id: 7, title: "Where the Crawdads Sing"), ] struct BookEntity: AppEntity, Identifiable { static var typeDisplayRepresentation: TypeDisplayRepresentation = "Book" var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: "\(title)") } static var defaultQuery = BookQuery() var id: Int @Property(title: "Title") var title: String init(id: Int, title: String) { self.id = id self.title = title } } struct BookQuery: EntityQuery { func entities(for identifiers: [Int]) async throws -> [BookEntity] { return identifiers.map { id in books[id] } } } extension BookQuery: EntityPropertyQuery { static var properties = QueryProperties { Property(\BookEntity.$title) { EqualToComparator { str in { book in book.title == str } } ContainsComparator { str in { book in book.title.contains(str) } } } } static var sortingOptions = SortingOptions { SortableBy(\BookEntity.$title) } func entities( matching comparators: [(BookEntity) -> Bool], mode: ComparatorMode, sortedBy: [Sort<BookEntity>], limit: Int? ) async throws -> [BookEntity] { books.filter { book in comparators.allSatisfy { comparator in comparator(book) } } } } The example Shortcut first invokes entities(matching:mode:sortedBy:limit:) with comparators=[], sortedBy=[], limit=nil to fetch all Book entities. Next the filter step correctly applies the title contains filter but never calls entities(matching:mode:sortedBy:limit:) or even the body of the ContainsComparator. But the output is correctly filtered.
1
0
1.6k
Jul ’25
Accessing Safari URL using com.apple.security.scripting-targets entitlement?
I've created an app that grabs the current URL and Title/name from the frontmost window/tab of Safari or any of a number of Chromium browsers, using NSAppleScript. The app sits in the menu bar and can be summoned by shortcut key combo. let script = """ tell application \"Safari\" if not (exists front window) then return {\"\", \"\"} set theTab to current tab of front window set theURL to URL of theTab set theTitle to name of theTab return {theURL, theTitle} end tell """ if let appleScript = NSAppleScript(source: script) { let output = appleScript.executeAndReturnError(&error) if output.numberOfItems == 2 { let url = output.atIndex(1)?.stringValue let title = output.atIndex(2)?.stringValue if let url = url, !url.isEmpty { return (url, title) } } } If I sign an archived build and run it locally it works beautifully, no matter which browser I am using. But the URL/title grabbing breaks in sandbox due to permissions. I read and have been informed that I need to use com.apple.security.scripting-targets entitlement. The example for this is in WWDC 2012 and talks about accessing Mail compose window. <key>com.apple.security.scripting-targets</key> <dict> <key>com.apple.mail</key> <array> <string>com.apple.mail.compose</string> </array> </dict> However, I don't want to control the app or use any access groups, as I've looked through the sdef and Safari/Chrome do not provide any access groups whose contents I'm interested in. I just want to get the property/values of a window/tab. So I think I could be quite restrictive about the read-only access to two properties or objects that I need. That said, I'm going back and forth with TestFlight review kind of shooting in the dark. I need help! So I figure it's time to ask: what content should my entitlement have? Or am I on the wrong path entirely? I know it's possible because an app called Neptunes does it to get properties from Music.app Many thanks in advance, matt
1
0
121
Jun ’25
Transfer meta data from AppIntent to main app on `continueInForeground`
Hello! I am excited to try out the new continueInForeground API with iOS 26. I was wondering, what is the suggested way to transport meta data to the main app? Before, with SiriKit intents I would use the .onContinueUserActivity() API and were able to pass a NSUserActivity from the Shortcut to the Main app. Now, with the continueInForeground() call I am not sure – what would be your suggestion? Of course, I can store some data in UserDefaults, but that feels like a workaround. Happy to get some input on this! Thanks a lot and have a great day!
0
0
112
Jun ’25
How to conditionally add AppShortcut to appShortcuts list in AppShortcutsProvider
I am trying to add certain shortcuts based on user eligibility for a feature, however I get an error if i try to use conditions in appShortcuts of AppShortcutsProvider. if I use static list to update the shortcuts and use static shortcut list in appShortcuts of AppShortcutsProvider - shortcuts are not displayed. Can anyone help with an example to update appShortcuts of AppShortcutsProvider dynamically. Is that supported at all?
1
0
57
Jun ’25
How to donate IndexedEntity, if required in iOS 26
In the Get to Know App Intents WWDC session, it was said New this year, you can now add Spotlight indexing keys directly on properties. Annotating properties allows Spotlight to show more relevant information to customers. When donating indexed entities, the framework will handle creating the searchable item and attribute set for you. After donating entities, they can be found in Spotlight. How do you donate indexed app entities? Making app entities available in Spotlight seems to state it's not necessary to donate entities: The system can automatically extract the keys for Spotlight indexing at compile time and store them in the App Intents metadata that Xcode generates as part of your app’s bundle. As a result, Spotlight indexing is faster and can find your app entities without launching your app, and without you having to explicitly donate the entities to Spotlight. You also don’t need to manually update or remove entities from the Spotlight index when your app’s data changes. Say I have a CarEntity. The user can create/update/delete cars at any time. What is the modern way to get cars to appear in Spotlight in iOS 26?
2
0
113
Jun ’25
How to inject parameter dependency at runtime in iOS App Intent
I am trying to create an App Intent that lets a user select a day in the itinerary of a trip. The trip has to be chosen before the days available can be displayed. When the PlanActivityIntentDemo intent is ran from the shortcuts app, the trip selected is not injected into the appropriate TripItineraryDayQueryDemo Entity Query. Is there a way to get the selected trip to be injected at run time from shortcuts app. Here's some code for illustration: // Entity Definition: import AppIntents struct ShortcutsItineraryDayEntityDemo: Identifiable, Hashable, AppEntity { typealias DefaultQuery = TripItineraryDayQueryDemo static var typeDisplayRepresentation: TypeDisplayRepresentation = "Trip Itinerary Day" var displayRepresentation: DisplayRepresentation { "Trip Day" } var id: String static var defaultQuery: DefaultQuery { TripItineraryDayQueryDemo() } init() { self.id = UUID().uuidString } } struct TripItineraryDayQueryDemo: EntityQuery { // This only works in shortcut editor but not at runtime. Why? How can I fix this issue? @IntentParameterDependency<PlanActivityIntentDemo>(\.$tripEntity) var tripEntity @IntentParameterDependency<PlanActivityIntentDemo>(\.$title) var intentTitle func entities(for identifiers: [ShortcutsItineraryDayEntityDemo.ID]) async throws -> [ShortcutsItineraryDayEntityDemo] { print("entities being called with identifiers: \(identifiers)") // This method is called when the app needs to fetch entities based on identifiers. let tripsStore = TripsStore() guard let trip = tripEntity?.tripEntity.trip, let itineraryId = trip.firstItineraryId else { print("No trip or itinerary ID can be found for the selected trip.") return [] } return [] // return empty for this demo } func suggestedEntities() async throws -> [ShortcutsItineraryDayEntityDemo] { print("suggested itinerary days being called") let tripsStore = TripsStore() guard let trip = tripEntity?.tripEntity.trip, let itineraryId = trip.firstItineraryId else { print("No trip or itinerary ID found for the selected trip.") return [] } return [] } } struct PlanActivityIntentDemo: AppIntent { static var title: LocalizedStringResource { "Plan New Activity" } // The selected trip fails to get injected when intent is run from shortcut app @Parameter(title: "Trip", description: "The trip to plan an activity for", requestValueDialog: "Which trip would you like to plan an activity for?") var tripEntity: ShortcutsTripEntity @Parameter(title: "Activity Title", description: "The title of the activity", requestValueDialog: "What do you want to do or see?") var title: String @Parameter(title: "Activity Day", description: "Activity Day") var activityDay: ShortcutsItineraryDayEntity func perform() async throws -> some ProvidesDialog { // This is a demo intent, so we won't actually perform any actions. .result(dialog: "Activity '\(title)' planned") } }
0
1
108
Jun ’25
Writing unit tests for AppIntent with a @AppDependency declared
I am trying to write a unit test for an AppIntent and override the AppDependencyManager so I can inject dependencies for the purposes of testing. When I run a test, the app crashes with: AppIntents/AppDependencyManager.swift:120: Fatal error: AppDependency of type Int.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. App Intent: import AppIntents struct TestAppIntent: AppIntent { @AppDependency var count: Int static var title: LocalizedStringResource { "Test App Intent "} func perform() async throws -> some IntentResult { print("\(count)") return .result() } } extension TestAppIntent { init(dependencyManager: AppDependencyManager) { _count = AppDependency(manager: dependencyManager) } } Unit Test import Testing import AppIntents @testable import AppIntentTesting struct TestAppIntentTests { @Test("test") func test() async throws { let dependencyManager = AppDependencyManager() dependencyManager.add(dependency: 5) let appIntent = TestAppIntent(dependencyManager: dependencyManager) _ = try await appIntent.perform() } }
1
0
86
Jun ’25
Shortcut automation to make PDF
Hi! I am using the Automations in shortcuts in macOS 26 dev beta 1 and I have all my shortcuts working except this one. Why?(photo included). All the others are very similar except they do other things not make pdf. They work. Why does this one not. I tried changing the extension to .doc, or .docx instead of doc and docx I tried using if name ends in .docx I tried file filtering nothing. Any ideas? Thanks!
2
0
93
Jun ’25
How to initialize OpenIntent parameter when returning OpensIntent in perform
I have an app that lets you create cars. I have a CarEntity, an OpenCarIntent, and a CreateCarIntent. I want to support the Open When Run option when creating a car. I understand to do this, you just update the return type of your perform function to include & OpensIntent, then change your return value to include opensIntent: OpenCarIntent(target: carEntity). When I do this, I get a compile-time error: Cannot convert value of type 'CarEntity' to expected argument type 'IntentParameter<CarEntity>' What am I doing wrong here? struct CreateCarIntent: ForegroundContinuableIntent { static let title: LocalizedStringResource = "Create Car" @Parameter(title: "Name") var name: String @MainActor func perform() async throws -> some IntentResult & ReturnsValue<CarEntity> & OpensIntent { let managedObjectContext = PersistenceController.shared.container.viewContext let car = Car(context: managedObjectContext) car.name = name try await managedObjectContext.perform { try managedObjectContext.save() } let carEntity = CarEntity(car: car) return .result( value: carEntity, opensIntent: OpenCarIntent(target: carEntity) // FIXME: Won't compile ) } } struct OpenCarIntent: OpenIntent { static let title: LocalizedStringResource = "Open Car" @Parameter(title: "Car") var target: CarEntity @MainActor func perform() async throws -> some IntentResult { await UIApplication.shared.open(URL(string: "carapp://cars/view?id=\(target.id)")!) return .result() } }
2
0
122
Jun ’25
Use UnionValue For AppIntent Parameter
I'm currently trying to use the new @UnionValue macro. From what I understood, it allows multiple types for a parameter. I created the following enum: @UnionValue enum IntentDuration { case int(Int) case duration(Measurement<UnitDuration>) } Then, I tried to use it in the following AppIntent: struct MyIntent: AppIntent { static let title: LocalizedStringResource = "intent.title" static let description = IntentDescription("intent.description") static let openAppWhenRun: Bool = true @Parameter var duration: IntentDuration @Dependency private var appManager: AppManager @MainActor func perform() async throws -> some IntentResult { // My action return .result() } } However, I get the following error from Xcode at the @Parameter line: 'init()' is unavailable Did I wrongly understand how this works? Is there another way to accept multiple types for a parameter? I didn't manage to find any docs on this.
2
0
256
Jun ’25
App Shortcuts - No Flexible Matching Assets
My app uses App Intents to create App Shortcuts. When I build and run my app in Xcode, the App Shortcuts Preview tool (under Product menu) shows the following message: No Flexible Matching Assets This target is for a platform which is not supported by Flexible Matching or does not have Flexible Matching enabled. All of my project's targets are iPhone only with a minimum deployment of 18.0. In the build settings for this project, Enable App Shortcuts Flexible Matching is set to Yes. (build settings reference) Any guidance on how to troubleshoot this? Thank you!
0
0
81
Jun ’25
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.
6
0
114
Jun ’25
Avoiding Shortcut Intent Timeout When Uploading or Downloading Large Files
Hey everyone, I have an issue I'm running into – maybe someone has the expertise to help! I've created an app that adds Intents to the Shortcuts app, to interact with S3-compatible object storage. Everything works fine, until you decide to upload/download a large file, that your internet connection cannot handle in the ~30-second intent timeout. I've explored uploading files with a background task which seems to work somehow, but the bigger issue would be downloading larger files, as other parts of the subsequent shortcut may rely on it. To the question: Is there some way of increasing the timeout for a shortcuts intent, or a way to "trick" shortcuts into letting my custom intents download/upload files without timing out? Thanks so much!
0
0
62
Jun ’25