AppleScript

RSS for tag

AppleScript allows users to directly control scriptable Macintosh applications as well as parts of macOS itself.

Posts under AppleScript tag

94 Posts
Sort by:
Post marked as Apple Recommended
1.1k Views
I created an app that uses AppleScript to automatically convert .numbers files to .csv by opening it in Numbers and using the Export function. After one of the recent updates¹, in Xcode 11.5 (macOS 10.15.5) this no longer works. It shows the error: osacompile: no such component "AppleScript". I get the same error when I manually run the osacompile command in Terminal. ¹The last time I successfully compiled it was on 15 October 2019, so I was already running Catalina, but I don't know which of the updates since then broke it. How to reproduce Even without a valid test.applescript file, this is an easy way to reproduce it: /usr/bin/osacompile -l AppleScript -d -o test.scpt test.applescript This command gives me the same error. A simple way to reproduce it in Xcode is to create a new project and make it an AppleScript App. It can also be reproduced by using this project: https://github.com/hhas/Swift-AppleScriptObjC It's impossible to compile now. Can anyone confirm if this is a bug in macOS / Xcode or just on my system?
Posted
by
Post not yet marked as solved
0 Replies
492 Views
I was wondering if anyone knew how to make an auto clicker that would only work if the left click button on the mouse was held down and once you aren't holding down left click on the mouse, it would stop clicking?
Posted
by
Post not yet marked as solved
1 Replies
832 Views
Hello! I made an AppleScript that uses variables that changes by 1 every second, in the original version, it just tells System Events to type, but I kept getting errors so I changed it to tell System Events to activate and type something. The code works, but on the lines of code that tell System Events to activate, at a random time I get an error saying System Events is not running on the line of code telling it to activate. I am very confused. I will attach the error message as well as the code. The code is from a friend, I am just posting it for him. Script Error Application isn't running tell application "System Events" to activate tell application "System Events" to activate set beg to 0 set mc to 0 set hour to 0 set search to 0 set pet to 0 set hl to 0 set ud to 0 set pm to 0 set ud to 0 set searchresult to 0 set listhl to {"h", "l"} set listpm to {"f", "k"} set listsearch to {"north pole", "advent calendar", "mistletoe", "christmas tree", "christmas card"} delay 1 set ud to some item of listhl set pm to some item of listpm set searchresult to some item of listsearch set reset to 0 delay 9 tell application "System Events" keystroke "pls daily" key code 36 delay 0.5 keystroke "pls beg" key code 36 delay 0.5 keystroke "pls hunt" key code 36 delay 0.5 keystroke "pls fish" key code 36 delay 1 keystroke "pls hl" key code 36 delay 2 keystroke ud key code 36 delay 2 keystroke "pls pm" key code 36 delay 2 keystroke pm key code 36 delay 2 keystroke "pls search" key code 36 delay 1 keystroke searchresult key code 36 set ud to 0 set pm to 0 set searchresult to 0 delay 1 set ud to some item of listhl set pm to some item of listpm set searchresult to some item of listsearch repeat set beg to beg + 1 set mc to mc + 1 set hour to hour + 1 set search to search + 1 set pet to pet + 1 set hl to hl + 1 delay 1 if hl = 22 then tell application "System Events" to activate tell application "Google Chrome" to activate tell application "System Events" set hl to 0 keystroke "pls hl" key code 36 delay 1 keystroke ud key code 36 set ud to 0 delay 1 set ud to some item of listhl end tell end if if beg = 47 then tell application "System Events" to activate tell application "Google Chrome" to activate tell application "System Events" keystroke "pls beg" key code 36 set beg to 0 end tell end if if mc = 62 then tell application "System Events" to activate tell application "Google Chrome" to activate tell application "System Events" set mc to 0 keystroke "pls hunt" key code 36 keystroke "pls fish" key code 36 delay 6 keystroke "pls pm" key code 36 delay 2 keystroke pm key code 36 set pm to 0 delay 1 set pm to some item of listpm end tell end if if hour = 3600 then tell application "System Events" to activate tell application "Google Chrome" to activate tell application "System Events" keystroke "pls hourly" key code 36 delay 1 keystroke "pls daily" key code 36 set hour to 0 end tell end if if search = 37 then set search to 0 tell application "System Events" to activate tell application "Google Chrome" to activate tell application "System Events" keystroke "pls search" key code 36 delay 1 keystroke searchresult key code 36 set searchresult to 0 delay 1 set searchresult to some item of listsearch end tell end if if pet = 1800 then set pet to 0 tell application "System Events" keystroke "pls pet pat" key code 36 keystroke "pls pet feed" key code 36 if reset = 50 then set reset to 0 tell application "System Events" to activate end if end tell end if end repeat end tell end end end end end end
Posted
by
Post not yet marked as solved
2 Replies
741 Views
Hi All, Back to scripting Quicktime with Applescript, I assess the following line now fails : open image sequence seq1 frames per second 24 What I want it to automate .mov generation form numerous and large jpeg image sets, in Quicktime, through pure Applescript or Automate. I have spent hours on Google to sort it out and it seems there are no recent talks on such an issue. What is the issue ? Any helps or scriptlet will be much appreciated
Posted
by
Post not yet marked as solved
3 Replies
601 Views
I just run a very simple NSAppleScript: "do shell script \"echo command\" with administrator privileges" However, I got error as below: NSAppleScriptErrorNumber = "-2147450879"; But it works fine on my friend‘s mac, anybody know how to solve this problem.
Posted
by
Post not yet marked as solved
2 Replies
2.3k Views
I have an applescript application created in Script Editor on macOSS 10.14.6 - it is save as a run time only application and iss signed with hardened runtime. I have the following keys in my plist: NSAppleEventsUsageDescription com.apple.security.automation.apple-events I was having issues running the applescript application and it was suggested that I run "tccutil reset ALL" in terminal. This removed all my apps from Security & Privacy/Privacy/Automation tab. Great. But now when I run the app I always get the Not Authorized to send Apple events to Finder. I never get prompted to allow access. How can I reset set it so asks for permissions?
Posted
by
Post marked as solved
10 Replies
1.3k Views
Since upgrading to Big Sur, sending AppleScript "do JavaScript" command to Safari runs extremely slowly. For example: tell application "Safari" set rslts to do JavaScript "document.title;" in document 1 end tell ... this used to take a split second in prior versions of the MacOS. Since upgrading to Big Sur, running this script results in a spinning pinwheel, the Safari's CPU usage ramps up to 100% and the command takes about 10 seconds to complete.
Posted
by
Post not yet marked as solved
1 Replies
383 Views
I am trying to fetch the active app using Apple Script. This code worked before updating to Monterey. Now I am getting time out every time I run this snippet. on getCurrentApp() try with timeout of 5 seconds tell application "System Events" set activeApp to name of first application process whose frontmost is true say activeApp end tell end timeout on error say "Timeout" end try end getCurrentApp off-topic: Is there any way to identify if my system is locked or trigger a script when "Lock screen" event occurs.
Posted
by
Post not yet marked as solved
0 Replies
442 Views
I have been searching the Internet for a solution to automatically update a Google sheet doc with a dynamic CSV file hosted in Google drive. I have come across some paid solutions but nothing that works for the do-it-yourself users. Linking a CVS file to a google sheet doc using the =IMPORTDATA(“”) works but does not update the google sheet when the CVS file changes. I am unsure if hosting the CSV file on Google drive creates issues when synching to a Google docs sheet.  Also, I try the Google script editor but was not able to make the Google sheet update automatically after setting up the update CVS function and trigger. Has anyone found a way to automatically update a Google sheet with a dynamic CVS file? Is this a simple or complicated process?
Posted
by
Post not yet marked as solved
1 Replies
338 Views
Hi There I'm trying to create a basic script that extracts some text from a webpage, but when I save I'm getting a Syntax error that I don't understand... ... please see screenshot. The second Set (Role1Result) is working fine. I'm a bit of a newbie at this, so any help really appreciated. Here's the relevant bit of code pasted: set tid to AppleScript's text item delimiters -- save them for later. set AppleScript's text item delimiters to startText -- find the first one. set liste to text items of SearchText set AppleScript's text item delimiters to endText -- find the end one. set extracts to {} repeat with subText in liste if subText contains endText then copy text item 1 of subText to end of extracts end if end repeat set AppleScript's text item delimiters to tid -- back to original values. return extracts end extractText --- roles --- set role0Result to extractText(input0, " <dd class="result-lockup__highlight-keyword"> <span data-anonymize="job-title" class="t-14 t-bold">", "</span> <span> at ") set role1Result to extractText(input1, " <dd class=\"result-lockup__highlight-keyword\"> <span class=\"t-14 t-bold\">", "</span> <span> ")
Posted
by
Post not yet marked as solved
2 Replies
347 Views
this is my script set SnakeDrawing to "0)))))))))" set AttackMessage to "You went to the snake with your brand new Iron Sword, As confident as a wolf you strike the snake and kill it ine one ****! proudly you open the chest and get another part of the map! you go through the door and find some food to eat, you rest for a minute or so and continue on your journey." set SnakeMessage to "You reached to the snake location and find a pathway but you can't barehandedly attack those snakes, why dont you check the shack treasure chest." set ShackMessage to "You enter the shack, there on the floor you find a chest. You open it and inside there was a Iron Sword [Automaticaly Equiped]" set ExplanitoryMessage to "since you had a good look you probably want to know what the little markings mean right? If you do then let me tell you. - is a door, _ is nothing but land, * is a treasure, V is you and ~~ is a snake different enemies will appear across different map sections" set MapForm1 to "XXXXXXXXXXXX XV___________X                    X_X---X___X~~X X_X__X___X  -  XXXXXXXXXXXX" display dialog "You awaken from what seems to be a deep slumber, noticing you have forgotten all knowledge puts fear into your heart. You have found a map on your lap" buttons {"Open", "Throw it out"} default button 1 if the button returned of the result is "Open" then display dialog MapForm1 buttons {"Had a good glance? You will have another chance to look again later."} else display dialog "This map pulses with energy, you couldn't convince yourself to throw it out so you opened it" buttons {"Continue"} end if if the button returned of the result is "Continue" then display dialog MapForm1 buttons {"Had a good glance? You will have another chance to look again later."} end if display dialog ExplanitoryMessage buttons {"I understand so LETS EXPLORE!"} display dialog "You have 2 areas to go to, either the snake or the shack, what do you pick?" buttons {"Shack", "Snake"} if the button returned of the result is "Shack" then display dialog ShackMessage buttons {"Awesome!"} else display dialog SnakeMessage buttons {"Continue to shack"} end if if the button returned of the result is "Continue to shack" then display dialog ShackMessage buttons {"Awesome!"} if the button returned of the result is "Awesome!" then display dialog AttackMessage buttons {"Great let’s continue!"} display dialog "The snake was a beautiful creature so I drew it on your notebook, want to see?" buttons {"Ok why not?", "Later"} if the button returned of the result is "Ok why not?" then display dialog SnakeDrawing buttons {"It's Beautiful!", "It looks terrible ;-;"} if the button returned of the result is "Later" then display dialog "Ok" buttons {"Continue"} if the button returned of the result is "It looks terrible ;-;" then display dialog "I'm starting to regret helping you out, please don't be mean" buttons {"Ok I won't be mean"} end if if the button returned of the result is "It's Beautiful!" then display dialog "Thanks! I worked really hard on it" buttons {"No problem!"} end if end if end if end if display dialog "The End For Now" buttons {"Ok ;("}
Posted
by
Post not yet marked as solved
1 Replies
477 Views
Below not a complete script: #!/usr/bin/osascript use framework "CoreWLAN" calling a function, such as scanForNetworks(withSSID ssid) Any pointer to documentation would be very helpful. I cannot find any guidance so far. I am reading the AppleScriptObjCQuickTranslationGuide page and it is helpful but I am still struggling.
Posted
by
Post not yet marked as solved
0 Replies
646 Views
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
Posted
by
Post not yet marked as solved
2 Replies
331 Views
I've just found that AppleScript applets which generate Open or Save dialogs (e.g. via NSPathControl's NSPathStylePopUp) automatically create a preference file in the user's home preferences folder. The file has the same name as the applet's ID (e.g. com.apple.script.id.myapplet.plist). The file might contain value-key pairs for NSNavLastRootDirectory, NSNavPanelExpandedSizeForOpenMode, NSWindow Frame NSNavPanelAutosaveName etc. I have Googled and search but have not been able to find documentation on this. Is there any documentation which explains this behaviour and provides advice on how to use it ? Thanks.
Posted
by
Post not yet marked as solved
0 Replies
539 Views
I'm trying to run Shortcuts programmatically on Monterey. My understanding is that the official API for this is via AppleScript to the Shortcuts Events process. I created a Shortcut that does Quicklook on the passed in file parameter. It works as a Finder action but I can't figure out how to get it to work when running it via AppleScript or Scripting Bridge. If I send a file, alias or POSIX file, I get a generic Shortcuts error 4. If I send a path as a string, it just does a preview of the string passed in, and not the contents of the file the path references. Anyone have any insight on how to get this working?
Posted
by
Post not yet marked as solved
0 Replies
255 Views
Currently, I am developing an application with AppleScript. I checked the official Reference below, but there is a point that I am not sure how to implement, so let me ask you a question. (https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/DisplayProgress.html) By using the progress command as shown in the script example below, we are trying to inform users how many times the repeat process has been completed. set progress total steps to 5 set progress completed steps to 0 repeat with a from 1 to 5 set progress completed steps to progress completed steps + 1 delay 0.2 end repeat delay 0.2 display dialog "Progress End" I am expecting that "If the progress total steps and completed steps match, progress description ends". Is it possible to implement as expected? If so, can you tell me how to do it?
Posted
by
Post not yet marked as solved
1 Replies
260 Views
The Applescript documentation includes the following example: Listing 15-14AppleScript: Coercing a string to an alias set theFilePath to "Macintosh HD:Users:yourUserName:Desktop:My File.txt" set theFilePath to theFilePath as alias When I try to run the following script on my iMac running Big Sur 11.5.2 tell application "Finder" activate set theFilePath to "InternalDrive:Users:Shared:Previously Relocated Items:Security:Photos & Scans:BakerFamily:ArmyFence.psd" set theFilePath to theFilePath as alias end tell return theFilePath I get to following error message: error "Can’t make "InternalDrive:Users:Shared:Previously Relocated Items:Security:Photos & Scans:BakerFamily:ArmyFence.psd" into type alias." number -1700 from "InternalDrive:Users:Shared:Previously Relocated Items:Security:Photos & Scans:BakerFamily:ArmyFence.psd" to alias Am I doing something wrong or has something changed? I have also noticed that Applescripts I used routinely to change to labels on files until a month or so ago now no longer work.
Posted
by