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

Iterate Window in Specified Application
I get the error code: System Events got an error: Can't get application of "Application Name" during this line repeat with currentWindow in every window of application foregroundApp of this code on run tell application "System Events" set foregroundApps to displayed name of (every process whose background only is false) as list repeat with foregroundApp in foregroundApps set appName to foregroundApp as text if exists (window 1 of process appName) then repeat with currentWindow in every window of application foregroundApp end repeat end if end repeat end tell end run I'm guessing I'm missing something like set x to foregroundApp as y repeat with currentWindow in every window of application x How do I get the windows of the application foreground app?
0
0
517
Sep ’23
Using AppleScript, how to confirm a folder action is actually removed?
I'm writing AppleScript to make a new folder action and attach it to a specified folder. In case there's already a folder action attached to the folder before make new folder action is executed, I want to delete that folder action already exists. tell application "System Events" repeat with i from 1 to count of folder actions if (path of folder action i) as string is equal to "/Users/foo/MyFolder" then delete folder action i exit repeat end if end repeat make new folder action at end of folder actions with properties {name:"MyFolderAction", path:"/Users/foo/MyFolder"} end tell However, it is still often that when make new folder action is executed, an error occured saying that "There is already a folder action with this path: /Users/foo/MyFolder". Maybe it's because that when make new folder action is executed, the delete folder action has not completed yet. Adding a delay 1 before make new folder action makes the error occured less fruequently, but not disappeared. Is there any method to confirm that the folder action is really deleted before make new folder action is executed?
0
0
402
Sep ’23
Iterate Window instead of Mass Operation
I'm trying to modify this code to work iteratively: on run {input, parameters} tell application id "com.apple.systemevents" to set the value of attribute "AXMinimized" of every window of every process to false end run Something along the lines of : on run {input, parameters} foreach windows of every process tell application id "com.apple.systemevents" to set the value of attribute "AXMinimized" to false end run Is this possible?
2
0
538
Aug ’23
Automated Mouse Moving
I am attempting to automate the movement of my mouse fully through Apple software. I have tried a variety of things, and I am now on the Dev Forums because I've ran out of ideas. Some of the things I have attempted are: Full Keyboard Access, Mouse Keys, Accessibility Keyboard with Panel Editor actions. Please, feel free to share any advice you may have. My goal is to only move the mouse enough for the computer to know it is active. That could be one pixel. Mouse keys works, but I can't get it to automate, I still have to click "u" and "o" to move the mouse. Thanks for any advice y'all may have! Have a blessed day!
0
0
412
Aug ’23
AppleScript File not open with write permission error
I have an applescript that works perfectly on my local machine. It opens the file and writes to it and then closes. My Applescript is being tested and saved as a .app so it is an application. When I put the application on my server to test out the user experience it never propely opens the file and gives me this error:"File not open with write permission.Finder got an error: File not open with write permission. (-61)"Why would this work on my local machine and not work after being downloaded from my server? I have tested that my path's are correct and like I mentioned everything works perfectly on my local MAC machine. Here is the section of my Applescript code that seems to be throwing the error:set motionFullPath to ("" & pathEffects & "" & effectPlugin & ":" & theFolders & ":" & motionFiles & "") as string set myFile to open for access file motionFullPath with write permission set endOfFile to (get eof myFile) as number if result > 0 then set theText to read myFile set eof myFile to endOfFile write "<!--uuid:" & theURL & "-->" & return & theText to myFile end if close access myFile
2
0
2.0k
Apr ’17
Remove ‘Fwd: ’ from an forwarded email subject
All works well, except that 'Fwd:' in the subject line, which I'd like to remove when forwarding tell application "Mail" set theMessage to item 1 of (get selection) set forwardedMessage to forward theMessage without opening window tell forwardedMessage make new to recipient at end of to recipients with properties {address:"a@b.com"} set message signature of forwardedMessage to signature "Blank" of application "Mail" set stringLength to (count subject of forwardedMessage) set subject of forwardedMessage to (characters 0 thru stringLength) as string send end tell end tell
0
0
396
Aug ’23
Not being prompted when removing a root CA
We have our own root CA that is installed with our application. For non-MDM installs, the system asks if the user wants to do that, which is all well and good. It also used to ask us when removing that certificate. It doesn't now. So now I am wondering if I dreamed it, except other people say they also got prompted and don't now. It's being installed and removed using the security command, in scripts.
1
0
617
Aug ’23
How to sudo command in xcode cloud ci_post_clone.sh?
I'm installing texturepacker in ci_post_clone.sh script using below command in Xcode Cloud workflow. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null brew install --cask texturepacker But I'm getting sudo warning in log. ==> Downloading https://www.codeandweb.com/download/texturepacker/6.0.2/TexturePacker-6.0.2.dmg ==> Installing Cask texturepacker sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required ==> Purging files for version 6.0.2 of Cask texturepacker Error: Permission denied @ dir_s_mkdir - /usr/local/Caskroom How can i fix this issue? Any idea or suggestions would be appreciated. Thank You
2
6
3k
Aug ’22
AppleScript Language Guide. open for access. The parameter is not specified in the syntax.
Here is the help for the "open for access" command. In the Syntax - Parameters section, the first parameter is not specified, but immediately write something in parentheses. In the "write" command, it is done differently. https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW31
1
0
430
Aug ’23
AppleScript. Split the string into parts by the separator character.
This code does not make sense, I would just like to get information based on it. set MyData to "MyData1|MyData2" on MyScript(MyData) set MyVar1 to "MyData1" set MyVar2 to "MyData2" return MyVar1 & "|" & MyVar2 end MyScript The text is passed in the code: "MyData1|MyData2". I need to divide it into two parts by the "|" symbol. And write each part into two variables: myVar1 and myVar2. How to do it? P.S. The problem is that only one parameter can be passed to on...end. I need to pass two. I'll pass one, then split it into two.
1
0
1.1k
Aug ’23
AppleScript. Tell application "TextEdit" - the syntax of all commands.
Where can I see the entire list of commands for the "TextEdit" program? For example, there is a code: tell application "TextEdit" activate make new document with properties {text:"XDXDXD"} end tell There are two commands in this code: activate make new document with properties {text:"XDXDXD"} Where can I see all the available commands for the "TextEdit" program?
2
0
537
Aug ’23
Extract .iwa files into .xml format
Hi all, I am trying to find a way to export the content of a .pages file into .xml format. That can be done saving the file to '09 version and then unzipping and working on the xml file. But I would like to do it also with .iwa files. I am trying to find a workaround to translate pages file on windows platform without need to pass through word extension, or the '09 format (in order to reduce DTP at its minimum). I am coding on Python... Thank you so much for any suggestion!
1
1
1.1k
Mar ’23
Automating Split Screen View
I would like to automate opening two finder windows in split-screen View (the full screen split view you get by hovering over the green full-screen button and selecting Tile Window, not the windows style maximize) If possible preferably via AppleScript but would be okay with Automator or shortcuts. Any help would be greatly appreciated. Running an M1 Air on Monteray. my current workaround is this AppleScript, however, I would like to be using split-screen so it's in its on mission control workspace. PS New to mac and Applescript. tell application "System Events" to set the autohide of the dock preferences to true tell application "Finder" close windows open ("/Users/arthur/" as POSIX file) set screenBounds to bounds of window of desktop set screenWidth to item 3 of screenBounds set screenHeight to item 4 of screenBounds set the position of the front Finder window to {0, 0} set the bounds of the front Finder window to {0, 0, screenWidth * 0.5, screenHeight * 1} make Finder window set the position of the front Finder window to {screenWidth * 0.5, 0} set the bounds of the front Finder window to {screenWidth * 0.5, 0, screenWidth, screenHeight * 1} set the target of Finder window 1 to ("/Users/arthur/Downloads" as POSIX file) activate end tell
2
0
1.6k
Aug ’21
Mac account detail window [Ventura]
Hello everyone, Up to Monterey, a script we use to make it easier for users to change the password on their local account on the computer has worked very well. But after Monterey, it no longer works. I've searched the web like crazy without finding any solution for Ventura. So I'm giving this form a shot in the hope that someone has a solution or something to help me along the way. The main problem is to go from Users and Groups in System setting to the account detail where you can click the button for changing password. Anyone have any idea? Code looks as follows: use AppleScript version "2.4" -- Yosemite (10.10) or later use framework "Foundation" use framework "AppKit" use scripting additions set userName to short user name of (system info) -- Create a dialog with 3 buttons display dialog "Mac Utility - user: " & userName buttons {"Change Password", "Forget Wi-Fi", "Cancel"} default button 1 with title "User Utilities" with icon caution -- Open Users and Groups if result = {button returned:"Change Password"} then tell application "Finder" to open file "Accounts.prefpane" of (path to system preferences) -- Show account details window -- This is where I'm stuck -- The rest of the script bellow else if.... The earlier code looked as bellow that doesn't work with Ventura. tell application "System Events" tell application process "System Preferences" delay 1 click button -1 of tab group 1 of window 1 end tell end tell Tanks in advance.
3
0
450
Jul ’23
How do I Select multiple rows in the "Open" dialog window in "Preview"
How would I select multiple rows programmatically (ie not using Keyboard or mouse simulation) in the "Open" dialog window in "Preview". Manual Steps I'd take to do this in OSX Ventura 13.4.1 Open the "Preview" application. From Preview's "File" menu, select "Open" Wait for the dialog box whose title is "Open" to appear Manually Select Row 1,3,5, and 7. Fingers crossed that this is possible. Thanks in advance!
1
0
378
Jul ’23
Trouble with automations when triggered | Shortcuts IOS 16.5.1
This is a very long battle trying to solve an issue with an automation I created in the Shortcuts app. I have been facing this issue on my old phone SE2 and now it's the same on my 12. I am running IOS 16.5.1 with the latest security patches/ updates. This issue has also been reported to apple support multiple times with no solution yet. I have tried restoring, deleting all apps., redownloading the Shortcuts app., Deleting the Siri Voices and redownloading them but nothing is helping! I have included Screen and Video recording for this issue for the benefit of the reader I am also explaining the problem/ challenge here in text. NOTE: I am also a VoiceOver user and have a sight impairment Created a personal automation on the Shortcuts app. When any of 2 alarms is topped, get weather, text and speak text. While creating the automation and running it to test, the automation works flawless and the Siri voice used to speak text sounds just like it should. This is covered in the first video link. The challenge: When the automation is triggered, i.e. when the alarm is stopped and the text is to be spoken; the Siri voice is all choppy and inconsistent. This is demonstrated in the second video. P.S. It happens with all English Siri voices irrespective of Language selected in the automation i.e. Australia, India, United Kingdom, United States etc. NOTE: It's the Siri voices I downloaded from: Settings/ accessibility/ Spoken content. Other voices downloaded work fine but they aren't as good and natural as Siri voices. automation how it should be working: https://www.youtube.com/watch?v=-7YxOVRf8WA automation how it works when triggered: https://www.youtube.com/watch?v=rq2rIJQV7cw&amp;list=PL8vG-Fmt9t_lLgPAxlA8qaKVksgc9b3y6&amp;index=2
0
0
682
Jul ’23
[Applescript] FaceTime can not move to second monitor
Recently we tested how to move app using Applescript as below picture and find some interesting phenomenon. The following coordinates are meant for the second screen, but only FaceTime cannot be moved to the second screen. It can only be moved within its own screen, while other apps can be smoothly moved to the second screen. Because the syntax is exactly the same, could you help to guide us what is wrong with the script? Sincerely, Thanks, Bruce
0
0
474
Jul ’23