Automation & Scripting

RSS for tag

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

Automation & Scripting Documentation

Post

Replies

Boosts

Views

Activity

Can't write a property through ScriptingBridge
Staring to use ScriptingBridge in Swift to enable faster scripting access to an external app (Devonthink) and therefore avoid having to use an AppleScript as a conduit to call a Swift command line utility and deal with its results. The plan is to be able to read the plaintext of a record (no problem) and change the record name in Devonthink based on its contents. But I can’t seem to write to a property, instead getting an error “Cannot assign to property: ‘***’ is immutable”. Any guidance how to get around this?
1
0
473
Jun ’24
Full uninstall of an app
Hello all, I am wondering if anyone can help me with writing a script that fully uninstalls an app with one click or can point me to a script already written please? So that when I click the script it uninstalls the app and leaves nothing behind. So when I click finder and use the search function with the name of the app, then click add and then name matches (input name of app) then click add and select system files are included, nothing comes up as the script has completely removed it from my system. I am Using Mac Mini M2 Pro 16gb ram and macOS Sonoma. Thank you
0
0
464
Jun ’24
AppleScript, Do Shell. How do I write the "test" command to the "script editor"?
Hello. How to write this command correctly on a Macbook, in the script editor, so that I can click the "Run script" button and the script will give the result: if there is no folder, then report that there is no folder, if there is a folder, then report that the folder exists. do shell script "test -d 'Users/user/Desktop/New folder'" Now, if the folder exists, an empty string ("") is returned, if the folder does not exist, the script editor reports that an error has occurred. In general, my task is to write a script that checks the existence of a folder.
12
0
1.1k
May ’24
Where can I read the help for all Do Shell Script commands?
Where can I read the help for all Do Shell Script commands? For example, there is a "test" command. Which reference book mentions this command? I.e. I want to go to some website, all the Do Shell Script commands will be there, and among these commands I will find the "test" command. Or are there no such directories and the programmer should randomly find commands on the Internet on random sites?
5
0
765
May ’24
Script to automount 1 local networkshare an 1 external networkshare
Hi, I have one Synology NAS at home and one Synology NAS on an external place. On my MacBook I want to create a script that first mount the local NAS, wait 30 seconds (to let OpenVPN startup and connecting to my DDNS) and mount the external NAS. When mounting both NASses, I will let the script checking if both shares still mounted and if not, try to remount. I've created the code below but it looks like the script only runs te first lines and only mount the local NAS. global startup set startup to true on idle if startup then mount_share("smb", "Lisa", "NAS_name", "Data/Mijn Afbeeldingen") set startup to false return 30 else mount_share("smb", "Lisa", "NAS_name", "Data/Mijn Afbeeldingen") mount_share("smb", "Lisa", "IP-external NAS", "Backup Lisa") return 120 end if end idle on mount_share(protocol, account, server, share) set x to 0 -- try a few time in case the server has to wake up first. -- don't do anything if the share is already mounted repeat until x > 4 or (list disks) contains share tell application "Finder" try mount volume protocol & "://" & account & "@" & server & "/" & share on error set x to x + 1 delay 30 end try end tell end repeat end mount_share Hopefully someone can help me
0
0
300
Jun ’24
"Vou" to "vouch" issue. Automatic text filling causing major issues for portuguese users.
Since apple has added the "no opt out" automatic completion of some words in the iphone keyboard, pr at least in the latest version of IOS 17.5.1 many users that try to use the portuguese word "vou" that means "going" ar suffering from constant replacing of the word to "vouch" even with the keyboard and phone language set to portuguese and autofill turned off.
1
0
676
Jun ’24
CoreDevice framework is unable to route iOS app's stdout
I am trying to automate the installation, launch, and monitoring of iOS apps. Historically we have used ios-deploy, but as of XCode 15 and iOS 17+, using ios-deploy no longer works. See issue The CoreDevice framework and xcrun's devicectl command has many of the features I require, but in contrast to ios-deploy, executing xcrun devicectl process launch --device <uuid> <bundle> does not route the launched app's stdout the the devicectl process. From the help menu, it looks like adding the --console flag will do exactly what I want, which routes the app stdout to the devicectl process and waits for the app to exit. However, if I try running xcrun devicectl process launch --console --device <uuid> <bundle> I receive the following error ERROR: The specified operation is not implemented on this device. (com.apple.dt.CoreDeviceError error 1 (0x01)) -------------------------------------------------------------------------------- ERROR: The operation couldn't be completed. (CoreDevice.ActionError error 2.) NSDebugDescription = This operation cannot be performed on this device. It's rather unclear on what the actual issue is, and I can't find any CoreDevice documentation online to help me deduce what these error codes refer to. Any help would be appreciated!
1
1
814
Jun ’24
App Intents vs. Lock Screen
I've been working on a project with App Intents and have hit a complete wall. The desire is to have an app that allows a person to place an order of something and have that order processed while in lock screen without any intervention. Is that workflow possible without having to unlock the screen? Under what circumstances can a task be handled without unlocking the device. Going over some of the documentation about older custom intents strongly implies that this was possible under certain circumstances.
1
0
615
May ’24
iOS Automation could not run because an internal error occurred
I am developing a shortcut for an application that is currently in production. The shortcut essentially involves opening the application and launching a notification so that the AppDelegate initiates a process to scan NFC tags. To achieve this, I have an AppIntent that overrides the variable openAppWhenRun = true and an AppShortcutsProvider to implement this intent. The problem arises when a user updates to the latest version of the application and tries to implement this shortcut through an automation. The following error appears: "When 'Reader' is detected" encountered an error: The action 'Scan DMA tags' could not run because an internal error occurred. This does not always happen, only on some devices. However, if we uninstall and reinstall the application, it works perfectly. But this is not a viable solution since the application uses a database and data loss from frequent uninstallations is not acceptable. Any solution? I have tried to replicate the error but have been unable to do so. This issue has occurred on both iOS 16 and iOS 17.
2
1
534
May ’24
Support for Automator app in macOS
Can someone update about the current state of the Automator app in macOS. Automator seems like a valuable tool for automating tasks on macOS but in the recent years I have noticed a growing emphasis on the Shortcuts app for automation. It would be great if you could clarify the following: • Current Status of Automator: Is there any official statement regarding the continued support of the Automator app in future macOS versions? • Future of Automator: Does Apple plan to introduce new features or updates for Automator in upcoming releases? • Indifference to Shortcuts App: From what I understand both the ‘Automator’ and the ‘Shortcuts’ app are used for creating workflows/shortcuts to automate tasks. What is it that Automator app has to offer which cannot be done using the Shortcuts app? assuming the continued support for the Automator app. Can all the automator workflows not be automated using the shortcuts app? I understand that Apple is constantly innovating and introducing new tools. However, clarity regarding the future of Automator would be helpful for users like myself. In addition, as a developer I wanted to offer some actions for my application in the Automator app, so that the user can make use of it to create some workflows. But from what I found in the apple documentation here, these action are created using the ‘Automator action’ Project type template in the xcode. However, in the current version of xcode 15, this project type seems to be missing. Does it indicate that apple no longer provides support for applications to create new automator action? If not, how can I provide automator actions for my xcode application?
1
0
675
May ’24
Capture the popup window in the Mac desktop by Apple Script
For our iOS inception e2e test, sometimes the test is blocked by the Mac pop-up window alert. The possible pop-up as follows: Java Access Pop-up Accessibility Pop-up SystemProperty Pop-up and so on...... In order to fetch the unexpected pop-up dialog window when executing e2e tests. I write a simple Apple script get_popup_windows.scpt as follows: tell application "System Events" set allProcesses to processes whose background only is false -- Log the count of allProcesses log "Number of processes found: " & (count of allProcesses) set dialogInfos to {} repeat with eachProcess in allProcesses try tell eachProcess log "Process Name: " & (name of eachProcess as text) set allWindows to (windows whose subrole is "AXStandardWindow" or subrole is "AXDialog") log "Number of allWindows found: " & (count of allWindows) repeat with eachWindow in allWindows set uiElements to UI elements of eachWindow log "eachWindow: " & (name of eachWindow as text) set the end of dialogInfos to {title:(name of eachWindow as text), processName:(name of eachProcess as text)} end repeat end tell end try end repeat end tell return dialogInfos However, when I execute the script: osascript get_popup_windows.scpt The result as follows: Number of processes found: 10 Process Name: Terminal Number of allWindows found: 1 eachWindow: scripts — osascript get_popup_windows.scpt — 143×41 Process Name: Google Chrome Number of allWindows found: 1 eachWindow: Gemini - Google Chrome - Will Process Name: sublime_text Number of allWindows found: 0 Process Name: Notes Number of allWindows found: 0 Process Name: Music Number of allWindows found: 0 Process Name: Finder Number of allWindows found: 0 Process Name: app_mode_loader Number of allWindows found: 0 Process Name: Simulator Number of allWindows found: 0 Process Name: app_mode_loader Number of allWindows found: 0 Process Name: Script Editor Number of allWindows found: 0 title:scripts — osascript get_popup_windows.scpt — 143×41, processName:Terminal, title:Gemini - Google Chrome - Will, processName:Google Chrome => I cannot fetch the target pop-up window in the Mac desktop. Please guide me if you have any suggestions, thanks.
1
0
649
May ’24
translation project only uses first and last items in a Numbers cell range
I need to translate various items from a Numbers file. I used chatGPT to help me write a script which receives a cell range and translates them using Google Translate. The problem I am having is that it only translates the first and last items in the desired cell range. Please help me integrate a way to have it translate the whole range, i.e (D435:D440). Here is the script: -- Define the document file path set filePath to "file path here" -- Define the sheet, table, and cell range set sheetName to "Sheet 1" set tableName to "Table 1" set cellRange to "D429:D433" -- Function to translate text from Spanish to English using Google Translate API on translateText(textToTranslate) set baseURL to "https://translate.googleapis.com/translate_a/single?client=gtx&sl=es&tl=en&dt=t&q=" set encodedText to do shell script "python -c \"import urllib, sys; print urllib.quote(sys.argv[1])\" " & quoted form of textToTranslate set translatedText to do shell script "curl -s \"" & baseURL & encodedText & "\"" set translatedText to my parseTranslatedText(translatedText) return translatedText end translateText -- Function to parse the translated text on parseTranslatedText(translatedText) try set translatedText to quoted form of translatedText set translatedText to do shell script "python -c \"import sys, json; print json.loads(sys.argv[1])[0][0][0]\" " & translatedText return translatedText on error errMsg return "Error translating text" end try end parseTranslatedText -- Function to get the contents of a cell range on getCellRangeValues(filePath, tableName, sheetName, cellRange) set cellValues to {} tell application "Numbers" set doc to open filePath tell sheet sheetName of doc set tbl to table tableName repeat with cellRef in words of cellRange set end of cellValues to value of cell cellRef of tbl end repeat close doc saving no end tell end tell return cellValues end getCellRangeValues -- Function to set the translated text in a cell range on setTranslatedValues(filePath, tableName, sheetName, cellRange, translatedValues) tell application "Numbers" set doc to open filePath tell sheet sheetName of doc set tbl to table tableName repeat with i from 1 to count of words in cellRange set cellRef to word i of cellRange set value of cell cellRef of tbl to item i of translatedValues end repeat close doc saving yes end tell end tell end setTranslatedValues -- Main translation process try -- Get the Spanish texts from the specified cell range set spanishTexts to getCellRangeValues(filePath, tableName, sheetName, cellRange) -- Translate the Spanish texts to English set translatedTexts to {} repeat with textToTranslate in spanishTexts set translatedText to translateText(textToTranslate) set end of translatedTexts to translatedText end repeat -- Set the translated texts in the specified cell range setTranslatedValues(filePath, tableName, sheetName, cellRange, translatedTexts) display dialog "Translation completed successfully." on error errMsg display dialog "Error: " & errMsg end try The only way i have been able to bypass cell access errors is by indicating both the sheet and table numbers. Also I found a post that metions using the word 'Item' when working with a specific cell in a cell range. Thank you for your help.
1
0
509
Mar ’24
Unable to set slider value in System Settings in macOS 13 or 14
I found this older post, which modifies the cursor size via AppleScript. I managed to update it to work in Ventura and Sonoma, but only in a kludgy manner. Here's the working code: set theSystemVersion to system version of (system info) tell application "System Settings" reveal anchor "AX_CURSOR_SIZE" of pane id "com.apple.Accessibility-Settings.extension" delay 1.0 tell application "System Events" if (text 1 thru 2 of theSystemVersion) is "13" then set contentView to group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Display" of application process "System Settings" else set contentView to group 3 of scroll area 1 of group 1 of list 2 of splitter group 1 of list 1 of window "Display" of application process "System Settings" end if set theSlider to slider 1 of contentView set stash to value of theSlider if value of theSlider is 1.0 then --set value of theSlider to 4.0 repeat while value of theSlider is less than 4 increment theSlider end repeat say "Big Mouse" using "Ralph" else --set value of theSlider to 1.0 repeat while value of theSlider is greater than 1 decrement theSlider end repeat say "Tiny Mouse" using "Ralph" end if stash end tell end tell The problem is the two commented out lines: In the original post, those commands work to set the slider to an exact value. In Ventura and Sonoma, they do nothing at all—no errors, just nothing. The script runs fine, but it won't change the cursor size. The only way I got it to work is via the method you see here—repeatedly incrementing or decrementing the value of theSlider until it was either 4 or 1. (The setting of 'stash' seems completely unnecessary, but I left it there anyway.) Does anyone know why the command to set a specific slider value is failing? I'd like to be able to set it in one pass, as this method is slow and ugly. thanks!
0
2
617
Mar ’24
Run a python script as a quick action in finder on selected folder
Hi, not sure if this forum is the right place to ask, but it’s extremely difficult to search the web for answers about shortcuts.app (must be the name…). I’m learning python currently and I’m trying to automate recurring tasks on my Mac easily. I have a python script as a first test-case that works (It basically makes a bunch of named folders). I use Apples Shortcuts.app to execute the python-file with the shell-script action. I start this script in Finder from the Quick Actions menu. The script creates my folders, but not in the selected folder when executing it, but always in my users home folder /Users/markus/. I suspect I have to somehow tell the Shortcut to take the currently selected folder as a variable or something. I tried to read the help but I don’t find anything useful and don’t understand the options of the Shell-Script Action in Shortcuts.app. Any ideas how I can get this to work? Or does anyone have a link to a good forum to ask questions about Shortcuts.app and automation? Thanks! Regards Markus
5
1
2.9k
Nov ’23
updating the recovery partition with the latest OS & Updates
Is anyone familiar with the Sonoma 14.4 update file? I asked LLM to help me write a script to update the recovery partition. It keeps suggesting files that were in the old InstallAssistant.pkg, but Sonoma is different. Is anyone familiar with the Sonoma setup and its file structure? Is there a way to update the recovery partition with the latest OS? Because when I restore my computer back to factory reset, it always restores the macOS which came with the Mac. I have a Mac mini M2. Below is the script I used: #!/bin/bash Function to display an error message and exit function display_error { echo "Error: $1" exit 1 } Path to the directory containing InstallAssistant.pkg pkg_directory="/Users/colinp/Downloads" Check if InstallAssistant.pkg exists in the specified directory if [ ! -f "$pkg_directory/InstallAssistant.pkg" ]; then display_error "InstallAssistant.pkg not found in $pkg_directory." fi echo "InstallAssistant.pkg found in $pkg_directory." Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." exit 0 fi Mount the InstallAssistant disk image echo "Mounting InstallAssistant disk image..." if ! hdiutil attach "$pkg_directory/InstallAssistant.pkg" -noverify -mountpoint /Volumes/InstallAssistant; then display_error "Failed to mount InstallAssistant disk image." fi Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Find the BaseSystem.dmg within the InstallAssistant disk image basesystem_dmg=$(find /Volumes/InstallAssistant -name "BaseSystem.dmg" -print -quit) Check if BaseSystem.dmg is found if [ -z "$basesystem_dmg" ]; then display_error "BaseSystem.dmg not found within InstallAssistant.pkg." fi echo "BaseSystem.dmg found." Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Determine the device identifier of the target disk recovery_partition=$(diskutil list | grep "Recovery HD" | awk '{print $NF}') if [ -z "$recovery_partition" ]; then display_error "Recovery partition not found." fi echo "Recovery partition found: $recovery_partition" Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Unmount the recovery partition echo "Unmounting the recovery partition..." if ! diskutil unmountDisk "$recovery_partition"; then display_error "Failed to unmount the recovery partition." fi Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Restore BaseSystem.dmg to the recovery partition echo "Updating the recovery partition. This may take a while..." if ! sudo asr restore --source "$basesystem_dmg" --target "$recovery_partition" --erase; then display_error "Failed to update the recovery partition." fi Detach the InstallAssistant disk image echo "Detaching InstallAssistant disk image..." if ! hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1; then display_error "Failed to detach InstallAssistant disk image." fi echo "Recovery partition update complete. any help is appreciated. Thanks in advance.
0
0
581
Mar ’24