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

Dynamic parameters in shortcuts
I need to have a dynamic parameter for Shortcuts, so a person can say something like Hey Siri, order a pizza with The parameter code in the appIntent is @Parameter(title: "Title") var itemName: String In the Shortcut I use: AppShortcut( intent: NewItemIntent(), phrases: [ "order \(\.$itemName) using \(.applicationName)" ], shortTitle: "Order Item", systemImageName: "sparkles" ) When I call it "hey Siri, order pizza using ***" where pizza should be passed via the parameter then handed off to the appintent. However, it ignores the spoken parameter in lieu of putting up a dialog asking "What's the name?" I can say "pizza" and it now works. How can I pick up the parameter without having to go to that second step as the code implies?
1
0
24
1d
NSUserActivity in application(_:continue:restorationHandler:) not recognized as INStartCallIntent
Hello, experts! I'm working on a VOIP application that handles audio calls and integrates with CallKit. The problem occurs when attempting to redial a previously made audio call from the system's call history. When I try to handle the NSUserActivity in the application(_:continue:restorationHandler:) method, it intercepts the INStartAudioCallIntent instead of the expected INStartCallIntent. Background Deprecation Warnings: I'm encountering deprecation warnings when using INStartAudioCallIntent and INStartVideoCallIntent: 'INStartAudioCallIntent' was deprecated in iOS 13.0: INStartAudioCallIntent is deprecated. Please adopt INStartCallIntent instead. 'INStartVideoCallIntent' was deprecated in iOS 13.0: INStartVideoCallIntent is deprecated. Please adopt INStartCallIntent instead. As a result, I need to migrate to INStartCallIntent instead, but the issue is that when trying to redial a call from the system’s call history, INStartAudioCallIntent is still being triggered. Working with Deprecated Intents: If I use INStartAudioCallIntent or INStartVideoCallIntent, everything works as expected, but I want to adopt INStartCallIntent to align with the current iOS recommendations. Configuration: CXProvider Configuration: The CXProvider is configured as follows: let configuration = CXProviderConfiguration() configuration.supportsVideo = true configuration.maximumCallsPerCallGroup = 1 configuration.maximumCallGroups = 1 configuration.supportedHandleTypes = [.generic] configuration.iconTemplateImageData = UIImage(asset: .callKitLogo)?.pngData() let provider = CXProvider(configuration: configuration) Outgoing Call Handle: When making an outgoing call, the CXHandle is created like this: let handle = CXHandle(type: .generic, value: callId) Info.plist Configuration: In the info.plist, the following key is defined: <key>NSUserActivityTypes</key> <array> <string>INStartCallIntent</string> </array> Problem: When trying to redial the audio call from the system's call history, the NSUserActivity received in the application(_:continue:restorationHandler:) method is an instance of INStartAudioCallIntent instead of INStartCallIntent. This happens even though INStartCallIntent is listed in NSUserActivityTypes in the info.plist and I want to migrate to the newer intent as recommended in iOS 13+. Device: iPhone 13 mini iOS version 17.6.1
0
0
39
1d
Difficulties with Get Contents of URL
I’ve created several shortcuts that tell me the stock price of a given company. The shortcut queries Yahoo Finance using Get Contents of URL, with the URL https://finance.yahoo.com/quote/TICKER SYMBOL/, for example https://finance.yahoo.com/quote/PLTR/ for Palantir or https://finance.yahoo.com/quote/AAPL/ for Apple, etc. Then it uses RegEx to parse out the numbers which it then formats and displays in a notification. Simple. It works great for several stocks, but for some reason, it does not work correctly for Palantir. It shows an older “previous close” price. Oddly, when I go to the website myself, it shows me the current stock price. So for today Mar 21 https://finance.yahoo.com/quote/PLTR/ shows me $90.96 (correct) but the shortcut, via Get Contents of URL, shows $87.39 (incorrect). This $87.39 price is listed further down in the page as a "previous close” price. I don’t get it. Here is a link to my Palantir shortcut: https://www.icloud.com/shortcuts/edea6ee0261245f49b078efc74d632dd Here is a link to my Apple shortcut: https://www.icloud.com/shortcuts/54a416393203432aa356fe76373e3f8b So the question is, why does Get Contents of URL show an old stock price but when I go to the site myself, it shows the correct stock price … and only for Palantir? I have about six shortcuts running correctly. Palantir is the only one that does not work. Been banging my head on this one for weeks. Any advice would be much appreciated. Thank you, Rob
0
0
8
4d
Applications Scripts denied
Hi all, I'm developing a sandboxed Mac OS app that generates and compiles AppleScript files to automate tasks in Pages (and other iWork apps). The app creates an AppleScript file and writes it to the NSApplicationScriptsDirectory (i.e., ~/Library/Application Scripts/com.example.app), then compiles and executes it via NSUserAppleScriptTask. On Mac OS Ventura, however, I get the following error in the console when trying to write the file: [PagesModifier] Error creating or compiling the script: You are not allowed to save the file "PagesModifier_...applescript" in the folder "com.example.app" Here are my current entitlements: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.application-groups</key> <array/> <key>com.apple.security.automation.apple-events</key> <array> <string>com.apple.iWork.Pages</string> <string>com.apple.iWork.Numbers</string> <string>com.apple.iWork.Keynote</string> </array> <key>com.apple.security.files.user-selected.read-write</key> <true/> <key>com.apple.security.scripting-targets</key> <dict> <key>com.apple.iWork.Keynote</key> <array> <string>com.apple.iWork.Keynote</string> </array> <key>com.apple.iWork.Numbers</key> <array> <string>com.apple.iWork.Numbers</string> </array> <key>com.apple.iWork.Pages</key> <array> <string>com.apple.iWork.Pages</string> </array> </dict> <key>com.apple.security.temporary-exception.apple-events</key> <array> <string>com.apple.iWork.Pages</string> <string>com.apple.iWork.Numbers</string> <string>com.apple.iWork.Keynote</string> </array> <key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key> <array> <string>Library/Application Scripts/com.example.app</string> </array> </dict> </plist> I suspect the issue might be due to sandbox restrictions on dynamically creating or modifying the Application Scripts directory on Ventura. Has anyone experienced something similar or have any suggestions on how to work around this? Thanks in advance for your help!
6
0
51
6d
App Intents doesn't works in widgets
I’m trying to develop a widget with a button that triggers an app intent. I integrated the app intent into my app within a separate app framework. I tested it with Shortcuts and Siri, and it works well—it opens the app on the required screen. However, when I added a button Button(intent: MyIntent()) to my widget, it doesn’t work at all. The only clue I found is the following message in the Xcode debug console: “No ConnectionContext found for (some big integer)” when I tap on the widget's button. However, I see the same message when running it through the Shortcuts app, and in that case, it works fine. Does anyone know what might be causing this issue? My Intent: public struct OpenTextInputIntent: AppIntent { public static var title: LocalizedStringResource = "Open text input" public static var openAppWhenRun: Bool = true @Parameter(title: "Predefined text") public var predefinedText: String @Dependency private var appCoordinator: AppCoordinatorProtocol public init() { } public func perform() async throws -> some IntentResult { appCoordinator.openAddMessage(predefinedText: predefinedText) return .result() } } My widget's view: struct SimpleWidgetView : View { var entry: SimpleWidgetTimelineProvider.Entry var body: some View { ZStack(alignment: .leadingTop) { button } } private var button: some View { Button(intent: OpenTextInputIntent()) { Image(systemName: "mic.fill") .resizable() .aspectRatio(contentMode: .fit) .iconFrame() } .buttonStyle(PlainButtonStyle()) .foregroundStyle(Color.white) .padding(10) .background(Circle().fill(Color.accent)) } } Intents Registration in the app target: struct MyAppPackage: AppIntentsPackage { static var includedPackages: [any AppIntentsPackage.Type] { [FrameworkIntentsPackage.self] } } struct MyAppShortcutsProvider: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: OpenTextInputIntent(), phrases: ["Add message in \(.applicationName)"], shortTitle: "Message input", systemImageName: "pencil.circle.fill" ) } } What I'm missing?
0
0
14
6d
AppIntent, should I delete previous donations to the system and how?
Hi, In my application I am donating AppIntent instances that I have to the system using the donate() API. I recently came across this article that talks about deleting donations but it does not mention how to handle AppIntent instances. I am wondering when working with dynamic AppIntents (with different properties that can change in the future), should I be worried about "outdated" donated AppIntent instances? And if yes how can I delete previously donated AppIntent instances.
0
0
160
1w
Displaying an email in mail preview pane by message ID
Hi, I want to open an email message with AppleScript. Everything is working correctly, but in the Mail app, instead of focusing on targetMessage, it highlights the email after the target message. When I use: tell targetMessage to open the correct email opens in new window but the wrong email is highlighted in the Mail app list. tell application "Mail" activate set targetAccount to missing value repeat with anAccount in every account if name of anAccount is "AccountName" then set targetAccount to anAccount exit repeat end if end repeat if targetAccount is not missing value then set targetBox to missing value repeat with aBox in mailboxes of targetAccount if name of aBox is "MailboxName" then set targetBox to aBox exit repeat end if end repeat if targetBox is not missing value then set targetMessage to missing value set oneWeekAgo to (current date) - (7 * days) set filteredMessages to (every message of targetBox whose date received ≥ oneWeekAgo) repeat with aMessage in filteredMessages try if message id of aMessage is "MessageID" then set targetMessage to aMessage exit repeat end if end try end repeat if targetMessage is not missing value then if (count of message viewers) > 0 then set mailViewer to message viewer 1 else set mailViewer to make new message viewer end if tell mailViewer set selected mailboxes to {targetBox} delay 0.2 set selected messages to {targetMessage} end tell return "Found" else return "Message Not found" end if else return "Folder Not found" end if else return "Account Not found" end if end tell Why is this behavior happening?
1
0
155
1w
Does DynamicOptionsProvider work on watchOS?
I'm curious, why DynamicOptionsProvider is available on watchOS? Is there any way to present options to the user? For example in Emoji Rangers project: struct EmojiRangerSelection: AppIntent, WidgetConfigurationIntent { static let intentClassName = "EmojiRangerSelectionIntent" static var title: LocalizedStringResource = "Emoji Ranger Selection" static var description = IntentDescription("Select Hero") @Parameter(title: "Selected Hero", default: EmojiRanger.cake, optionsProvider: EmojiRangerOptionsProvider()) var hero: EmojiRanger? struct EmojiRangerOptionsProvider: DynamicOptionsProvider { func results() async throws -> [EmojiRanger] { EmojiRanger.allHeros } } func perform() async throws -> some IntentResult { return .result() } } On watchOS we usually use recommendations() to give the user predefined choice of configured widgets. Meanwhile in AppIntentProvider recommendations are empty: struct AppIntentProvider: AppIntentTimelineProvider { ... func recommendations() -> [AppIntentRecommendation<EmojiRangerSelection>] { [] } } Does it imply that there's a way to use DynamicOptionsProvider on watchOS somehow? BTW, WidgetConfiguration.promptsForUserConfiguration() is one of the methods that are not available on watchOS. And also, the Emoji Ranger project doesn't show widgets (complications) on watchOS out of the box.
0
2
201
1w
AppIntents + CSSearchableItemAttributeSet: only displayName indexed?
On iOS 18, I'm trying to index documents in Spotlight using the new combination of AppIntents+IndexedEntity. However, I don't seem to be able to index the textContent of the document. Only the displayName seems to be indexed. As recommended, I start with the defaultAttributeSet: /// I call this function to index in Spotlight static func indexInSpotlight(document: Document) async { do { if let entity = document.toEntity { try await CSSearchableIndex.default().indexAppEntities([entity]) } } catch { DLog("Spotlight: could not index document: \(document.name ?? "")") } } /// This is the corresponding IndexedEntity with the attributeSet @available(iOS 18, *) extension DocumentEntity { var attributeSet: CSSearchableItemAttributeSet { let attributeSet = defaultAttributeSet attributeSet.title = title attributeSet.displayName = title attributeSet.textContent = docContent attributeSet.thumbnailData = thumbnailData attributeSet.kind = "document" attributeSet.creator = Constants.APP_NAME return attributeSet } } How can I have more that the displayName to be indexed? Thanks :-)
5
0
196
1w
Siri Shortcut Phrases iOS -17
I made a set of Siri Shortcuts in my app with the AppShortcutsProvider, and they each have a set of phrases. I can activate the shortcuts via Siri phrases or Spotlight search on iOS 18+, but not on iOS -17. I've checked the documentation and see that AppShortcutsProvider is supported from iOS 16+, so I don't understand why I can't view the shortcuts in Spotlight or activate them with Siri unless it's at least iOS 18. Any thoughts?
2
0
207
1w
Using Automator
Hi Here is my problem. I have a large number of portrait pictures in my adobe lightroom catalogue which I need to email to the subjects of the portraits. These peoples names and email addresses are stored in my pictures metadata and I am able to export the pictures with accompanying text or CSV files containing the names &amp; addresses. What I want to do is export the pictures in bulk and automagically create and send individual emails for each picture, preferably with the persons name in the salutation at the start of the email. I have done some googling trying to find a solution to this. I think that I need to use automator. (The lightroom option of mailing directly from within the programme isn't going to do the job, each mail would need to be addressed and written by hand each time). I have been playing around with it, but can see no way to populate the email address field or add the attachment. Can anyone help me out, with even just the basic outline, of how this would be achieved please?
0
0
103
1w
Start multiple Live Activities in the perform() of App Intents
In my case, when two functions that start each Live Activity(not connected each other) are performed in LiveActivityIntent's perform(), it seems that only one will start. (It's the same to start independently with two Task{}) And, set one to 'opensIntent' and separate it by opening another LiveActivityIntent, the result is same. Also, every time I tap the Intent directly in the shortcut app, one activity will end within a matter of seconds, even if there are two for a while. But, If openAppWhenRun to true, it seem to works without any problems. I would appreciate it if you could give me a tip to fix this problem.
0
0
106
1w
WidgetInfo - intent is nil until edit face
We have a watchOS app that provides many configurable widgets. Those widgets are configured and installed with help of AppIntent: public struct RectComplAppIntent: AppIntent, WidgetConfigurationIntent, CustomIntentMigratedAppIntent { @Parameter(title: "Style") var style: String? .... } However when I print WidgetInfos with getCurrentConfigurations(), I sometimes got nil for configuration. At the same time widgets are not loaded. Exact steps: User installs the pre-cofnigured .watchface. Complications are not loaded since configuration is missing. I print getCurrentConfigurations() and get entries like this: WidgetInfo: - configuration: nil - widgetConfigurationIntent: nil - family: accessoryRectangular - kind: Rectangle Then user force-touches a face and opens editing mode. Returns to watch app, prints infos: WidgetInfo: - configuration: <INIntent: 0x780d290> { style = vol1Logo; } - widgetConfigurationIntent: nil - family: accessoryRectangular - kind: Rectangle – Suddenly intent appears with the correct style and complications start to show up. How do you think, why it happens? Why after .watchface install all the WidgetInfo has nil intent (configuration)? What helps them to load later? You can try this face yourself: https://cdn.watchfaces.co/watchfaces/glance-minimalist.watchface
1
0
192
1w
syntax errors when working with folders that have “‘“ in it such as “greg’s folder"
I'm unable to fix syntax errors when using folders such as “greg’s folder" error "86:87: syntax error: Expected “"” but found unknown token. (-2741)" number 1 i’ve created an apple script to run python tool to extract “.rpa” files. the script works well except to selecting games that are in a folder with “‘". any ideas to properly to this? thank you. -- Function to escape special characters in POSIX paths for safe shell execution on escapePOSIXPath(originalPath) set AppleScript's text item delimiters to "'" set pathParts to text items of originalPath set AppleScript's text item delimiters to "'\\''" set escapedPath to pathParts as text set AppleScript's text item delimiters to "" -- Reset delimiters -- Wrap in single quotes return "'" & escapedPath & "'" end escapePOSIXPath -- Get the current app's POSIX path set currentAppPath to POSIX path of (path to me) -- Construct the expected path for rpatool.py set scriptPath to currentAppPath & "Contents/Resources/Scripts/rpatool.py" -- Check if rpatool.py exists set scriptExists to do shell script "test -e " & quoted form of scriptPath & " && echo true || echo false" if scriptExists is "false" then -- Ask user to select the rpatool.py file display dialog "rpatool.py was not found. Please select its location." set rpaToolFile to choose file with prompt "Select the rpatool.py script" of type {"public.python-script"} set scriptPath to POSIX path of rpaToolFile end if -- Escape the path for safe execution set scriptPath to escapePOSIXPath(scriptPath) -- Prompt user to select the game application set appFile to choose file with prompt "Select the Game app with RPA files" of type {"com.apple.application"} set appPath to POSIX path of appFile set gameFolderPath to appPath & "/Contents/Resources/autorun/game" -- Check if the 'game' folder exists set gameFolderExists to do shell script "test -d " & quoted form of gameFolderPath & " && echo true || echo false" if gameFolderExists is "false" then display dialog "The 'game' folder was not found in the selected app's directory. Exiting..." return end if -- Find all .rpa files in the game folder set fileList to paragraphs of (do shell script "find " & quoted form of gameFolderPath & " -name '*.rpa' -type f") -- Check if .rpa files exist if fileList is {} then display dialog "No .rpa files found in the 'game' folder. Exiting..." return end if -- Open Terminal and change directory set firstCommand to "cd " & quoted form of gameFolderPath do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & firstCommand & "\"") -- Process each .rpa file in Terminal display dialog "Extraction will start in Terminal and will process " & (count of fileList) & " .rpa files." repeat with aFile in fileList set aFile to escapePOSIXPath(aFile) set extractionCommand to "python3 " & scriptPath & " -x " & aFile -- Execute in Terminal try do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & extractionCommand & "\" in front window") delay 0.5 do shell script "osascript -e " & quoted form of "tell application \"Terminal\" to activate" on error errMsg display dialog "Error executing command: " & errMsg end try end repeat Test Run with error: tell current application path to current application --> alias "Macintosh HD:Users:Greg:Downloads:Ren'Py:RPA Extractor Mac 2.9.scpt" do shell script "test -e '/Users/Greg/Downloads/Ren'\\''Py/RPA Extractor Mac 2.9.scptContents/Resources/Scripts/rpatool.py' && echo true || echo false" --> "false" end tell tell application "Script Editor" display dialog "rpatool.py was not found. Please select its location." --> {button returned:"OK"} choose file with prompt "Select the rpatool.py script" of type {"public.python-script"} --> alias "Macintosh HD:Users:Greg:Downloads:Ren'Py:Test Game:rpatool.py" choose file with prompt "Select the Game app with RPA files" of type {"com.apple.application"} --> alias "Macintosh HD:Users:Greg:Downloads:Ren'Py:Test Game:Test Game.app:" end tell tell current application do shell script "test -d '/Users/Greg/Downloads/Ren'\\''Py/Test Game/Test Game.app//Contents/Resources/autorun/game' && echo true || echo false" --> "true" do shell script "find '/Users/Greg/Downloads/Ren'\\''Py/Test Game/Test Game.app//Contents/Resources/autorun/game' -name '*.rpa' -type f" --> "/Users/Greg/Downloads/Ren'Py/Test Game/Test Game.app//Contents/Resources/autorun/game/code.rpa /Users/Greg/Downloads/Ren'Py/Test Game/Test Game.app//Contents/Resources/autorun/game/fonts.rpa /Users/Greg/Downloads/Ren'Py/Test Game/Test Game.app//Contents/Resources/autorun/game/sounds.rpa" do shell script "osascript -e 'tell application \"Terminal\" to do script \"cd '\\''/Users/Greg/Downloads/Ren'\\''\\'\\'''\\''Py/Test Game/Test Game.app//Contents/Resources/autorun/game'\\''\"'" --> error "73:74: syntax error: Expected “\"” but found unknown token. (-2741)" number 1 Result: error "73:74: syntax error: Expected “\"” but found unknown token. (-2741)" number 1
2
0
158
2w
How to make a progress meter for an AppleScript that works with the Photos app
I wrote an AppleScript that takes a bunch of scanned jpegs with systematically named filenames and transfers information from the filename into the date and time fields. That all works fine, but I've got many more scans to do and I'd like to augment the script to include a progress meter because it takes a long time to run on e.g. 1000 photos. I've found basic progress meter examples online that involves commands like: set progress total steps to theImageCount set progress completed steps to 0 set progress description to "Processing Images..." set progress additional description to "Preparing to process." and they run OK in a separate dummy test case, however I'm getting syntax errors for such commands in my renaming script because (I think) they're inside a tell application "Photos" wrapper and it looks like Photos doesn't like those commands. A progress meter (in any AppleScript) should be a straightforward thing i.e. I can clearly define a total number of steps and I can clearly define the step number I'm currently on. I just want to display something like: I'd even be OK with just implementing something like: display dialog "blah blah" but that needs to be manually dismissed with each iteration of the loop, so that's no good. I also tried: display notification "blah blah" but that yields hundreds of notification boxes at the top right of my screen, so that's also impractical. I was even thinking maybe I could call some generic system progress meter with all the right variables via a "do shell script" command (although I have no idea how to do that). Something surely must be possible, but I just can't figure it out :-(. Could some kind soul please help me out. Thanks.
9
0
284
2w
A script to open files from Finder in Vim
Here is an AppleScript script to make it possible double-click files in Finder so that they will be opened in Vim, by Normen Hansen: https://github.com/normen/vim-macos-scripts/blob/master/open-file-in-vim.applescript (it must be used from Automator). I try to simplify it and also to make it possible to use it without Automator. To use my own version, you only need to save it as application instead, like this: osacompile -o open-with-vim.app open-with-vim.applescript and then copy it to /Applications and set your .txt files to be opened using this app. Here it is, it alsmost works: -- https://github.com/normen/vim-macos-scripts/blob/master/open-file-in-vim.applescript -- opens Vim with file or file list -- sets current folder to parent folder of first file on open theFiles set command to {} if input is null or input is {} or ((item 1 in input) as string) is "" then -- no files, open vim without parameters set end of command to "vim;exit" else set firstFile to (item 1 of theFiles) as string tell application "Finder" to set pathFolderParent to quoted form of (POSIX path of ((folder of item firstFile) as string)) set end of command to "cd" &amp; space &amp; (pathFolderParent as string) set end of command to ";hx" -- e.g. vi or any other command-line text editor set fileList to {} repeat with i from 1 to (theFiles count) set end of fileList to space &amp; quoted form of (POSIX path of (item i of theFiles as string)) end repeat set end of command to (fileList as string) set end of command to ";exit" -- if Terminal &gt; Settings &gt; Profiles &gt; Shell &gt; When the shell exits != Don't close the window end if set command to command as string set myTab to null tell application "Terminal" if it is not running then set myTab to (do script command in window 1) else set myTab to (do script command) end if activate end tell return end open The only problem is the if block in the very beginning: if input is null or input is {} or ((item 1 in input) as string) is "" then What is wrong here? How to make it work? (Assuming it already works fine if AppleScript is used using Automator.)
0
0
146
2w