AppleScript

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

Posts under AppleScript tag

72 results found
Post marked as unsolved
85 Views

NSAppleScript run Error

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.
Asked
by elsonpeng.
Last updated .
Post marked as solved
134 Views

Authorization error when porting an Applescript script using SpeechRecognitionServer to an Xcode project

I am trying to port an Applescript script which uses the SpeechRecognitionServer to an xcode project . (The script works fine when run from the Applescript editor). I've set up a simple xcode project that executes the script when I press a command button. This all works ok until the script hits the statement: language tell application "SpeechRecognitionServer" at which point I get the error: [AppDelegate displayName:]: Not authorized to send Apple events to SpeechRecognitionServer. (error -1743) I've added both NSSpeechRecognitionUsageDescription and NSAppleEventsUsageDescription with suitable string prompts to my Info.plist but this seems to have no effect. I'm not sure what else I need to do to get the script to run? I would be grateful for any help!
Asked
by Neddy.
Last updated .
Post marked as unsolved
134 Views

App has Completely Opened on the Mac?

Is there some way to check if an app has opened successfully on the Mac? This may sound like a silly question - if you open Pages, you know it's been successfully opened when you can see or edit your documents. But here's my situation: I'm running an Automator script to try to open all the apps I need on a given workday at once. Not only open but - here's the kicker - I want them grouped on particular Spaces. So I've got a kludge that's workable: I open up an app or two, switch Spaces, and then introduce an artificial delay in the execution of the Automator script for a set time, usually ~5 seconds. However, depending on whatever other background processes are in play at the moment, this hard-coded time only successfully lands the apps in the appropriate Space about 70% of the time. So back to the original question: is there a way of knowing when an app has successfully and completely opened? That way I could just check for that, and then move to the next Space and continue.
Asked
Last updated .
Post marked as unsolved
193 Views

OSACOMPILE_EXECUTE_ONLY does not make script execute only

I have an Apple Script added to my project and copying it to bundle resources. I have set OSACOMPILEEXECUTEONLY to yes under Build Settings. I compile my project, open the Application bundle and reach to myAppleScript.scpt under Resources folder. I am able to open myAppleScript.scpt in Script Editor and view its source. As per documentation OSACOMPILEEXECUTEONLY should make it executable and cannot view the original source in Script Editor.
Asked
by Deepa Pai.
Last updated .
Post marked as unsolved
186 Views

Applescript: javascript hyperlink

Hi, I am trying to write an AppleScript to click on a hyperlink on a webpage to export a file. Firstly there is a dropdown menu EXPORT AS, and once you click and expand the menu, I need to select and click XLSX (Microsoft [Excel) It's worth mentioning that I have zero knowledge of javascript, XPath, etc.. When I inspect the links, I can copy the following paths but have no clue what to do with them in terms of AppleScript... So any help is greatly appreciated! :) EXPORT AS (full XPath): /html/body/div[1]/div[1]/div[1]/div[4]/div[2]/div[3]/div[2]/div/button EXPORT AS (outer HTML): button id="ember532" class="btn btn-secondary dropdown-toggle ember-view" type="button" Export As  /button XLSX Microsoft Excel (full XPath): /html/body/div[1]/div[1]/div[1]/div[4]/div[2]/div[3]/div[2]/div/div/button[3] XLSX Microsoft Excel (outer HTML): button class="dropdown-item" tabindex="-1" type="button" data-ember-action="" data-ember-action-536="536"XLSX (Microsoft Excel)/button
Asked
Last updated .
Post marked as unsolved
553 Views

AppleScript to retrieve track properties in Music no longer working in Big Sur

I use AppleScript handlers within a Swift macOS app to retrieve song details for the currently playing track in Music. This has worked well through several iterations of macOS and Music up through Catalina. In Big Sur, the script continues to work with tracks that have been added to the user’s library. However, the AppleScript handlers no longer return any track properties (or anything at all) if the song is streaming, for instance when playing from a “Listen Now” playlist. In Catalina, the handlers return all the track properties whether or not the track has been added to the library. This problem exists even if I run the commands in Script Editor directly: success with added tracks, nothing with streaming tracks. A simple example: tell application "Music" set songTitle to name of current track return songTitle end tell I know from searching other forums that others are experiencing the same problem. Does anyone have more information about this? Is there a workaround? I tried other properties from the Music sdef, such as “current stream title”, but that doesn’t seem to work with any kind of track. As I recall, a previous macOS upgrade broke the same thing (I forget which version it was.), and it was eventually fixed. I hope that it gets fixed again soon. This functionality is critical to my app.
Asked
by packafoma.
Last updated .
Post marked as unsolved
110 Views

AppleScript: Open and save excel files

Hello - I have a bunch of excel files that are linked to each other, so when I update the main file, I need to open and save each of the files linked to this in order for the links to update. This is something I need to do daily, and opening and saving each of the files manually takes a lot of time when I guess this could be easily automated. I would need a code to do the following: open file1.xlsx select "update links" in the pop up when opening the file save file open file2.xlsx select "update links" in the pop up when opening the file save file open file3.xlsx etc... I appreciate the help, if someone has an east solution for this :) Thanks
Asked
Last updated .
Post marked as unsolved
100 Views

Preferences UI elements missing names in Big Sur

I have an AppleScript which sets my preferences, in this case for Finder. Prior to Big Sur, I was able to select a checkbox to toggle with the following: tell checkbox "Recents" to if value is 1 then click However, in Big Sur, the name property of these particular checkboxes appears to be missing. The following script run with Script Editor shows the difference: tell application "Finder" activate delay 1 end tell tell application "System Events" tell process "Finder" keystroke "," using {command down} delay 1 tell window "Finder Preferences" click button "Sidebar" of toolbar 1 delay 0.5 tell checkbox 1 get properties end tell end tell end tell end tell Prior to Big Sur, the results are: {minimum value:missing value, orientation:missing value, position:{47, 943}, class:checkbox, accessibility description:missing value, role description:"checkbox", focused:false, title:"Recents", size:{297, 18}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:missing value, selected:missing value, name:"Recents", description:"checkbox"} But on Big Sur (at least on the M1 MBP I have access to with Big Sur), the results are: {minimum value:missing value, orientation:missing value, position:{705, 234}, class:checkbox, accessibility description:"Recents", role description:"checkbox", focused:false, title:"", size:{14, 16}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:1, subrole:missing value, selected:missing value, name:missing value, description:"Recents"} You can see the name property on Big Sur is missing. Is this a bug? Some other preferences scripts I have appear to still work using the element names to interact with the UI, though I have not tested them all.
Asked
by rjernst.
Last updated .
Post marked as unsolved
115 Views

Allow PopUp in Safari 12 and above through terminal

I am trying to allow popup windows in Safari >= 12 through the command line. The default value in Safari >= 12 is Block and Notify and it is present under Preferences > Websites > Pop-Up Windows > When visiting other websites. Following works in Safari 11 and below but cant find similar commands for Safari >= 12 defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaScriptCanOpenWindowsAutomatically 1 defaults write com.apple.Safari WebKitJavaScriptCanOpenWindowsAutomatically 1
Asked
Last updated .
Post marked as unsolved
139 Views

Applescript "open image sequence" in Quicktime now fails, why ?

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
Asked
by jrs@adc.
Last updated .
Post marked as solved
152 Views

Use a shell script in swift (Xcode)

Hey, I don't know anything about swift but only about shell. That is why I ask here. My plan is to make an Application where you push a button to activate this script: sudo pmset -b sleep 0; sudo pmset -b disablesleep 1 I know, very simple. But how I can I make this? Thank you.
Asked
Last updated .
Post marked as unsolved
101 Views

Tables in Pages app interaction script

hi, does anyone know how to interact with tables in “move with text” mode in Pages app vía AppleScript or JavaScript (the one that I’m using) since we're able to control it in “stay on page” mode (format > arrange panel) with no problem, in my case with this code: Application(‘Pages’).documents[0].tables[0].cells[‘a1’].value(); I have found just one discussion about this previously in this link: https://discussions.apple.com/thread/7342718?answerId=29337466022#29337466022 but apparently it’s a bug that we cannot use it in “stay on page” mode, if it is, anyone knows if the bug is fixed in recent Pages updates? It’ll really be super helpful if this work since a table is totally useless in “stay on page” mode if you have a large table that jump pages and disappear parts of it. Regards!
Asked
Last updated .
Post marked as unsolved
145 Views

What is the workflow for code signing an AppleScript applet for Catalina/Big Sur?

I have an applet which installs an add-in for Microsoft Office. It requires automation to send AppleEvents to the PowerPoint application in order to register the add-in with the app. Here's a simplified example: tell application "Microsoft PowerPoint" 		display alert "bla bla bla" end tell I export this from the Script Editor as an Application, with Run Only enabled, and Don't Code Sign. I then manually sign it in Terminal with these three commands: xattr -cr "/users/username/documents/myApplet.app" codesign -f -s "Developer ID Application: bll bla bla" --options=runtime "/users/username/documents/myApplet.app" spctl --assess -vvv "/users/username/documents/myApplet.app" Note: --options=runtime is required to set hardened runtime for notarization. If I don't sign it, when I run the applet Gatekeeper prompts me to allow Apple events with the following message: "myApplet" wants to control "Microsoft PowerPoint". Allowing control will provide access to documents and data in "Microsoft PowerPoint", and to perform actions within that app. This script needs to control other applications to run Don't Allow / OK and when I click OK the applet runs, displaying the alert. But after signing and running it, I get the following error: Not authorised to send Apple events to Microsoft PowerPoint. Not authorised to send Apple events to Microsoft PowerPoint.(-1743) System Preferences shows the rule in the Automation tab with the checkbox ticked for myApplet / Microsoft PowerPoint. If I then remove the signature with the following command, the applet works as normal again: codesign --remove-signature "/users/username/documents/myApplet.app" What am I doing wrong?!
Asked
Last updated .
Post marked as unsolved
62 Views

applescript date formatting

I am running a filemaker 16 database in os 11.1 The database depends heavily on AppleScript to pull information out and write it to html files.  I haven’t run it for some time but I am having trouble with getting the right year from a Filemaker date field This used to work (simplifying the script to highlight the issue) tell application "FileMaker Pro Advanced" set x to cell "change Date" of current record end tell set y to date x return {day of y as text, items 1 thru 3 of (month of y as text) as text, year of y as text} But now it doesn’t.  The date is correctly pulled out of Filemaker as “2016-12-13” but the script returns day as 12 instead of 13, the month is right, but the year returns “12180” - I swear this used to work but something has changed.  Any ideas?
Asked
by zeno400.
Last updated .
Post marked as unsolved
106 Views

App development

I am an Art Director who has developed a hybrid App with the help of a company. My question is, after the app is on the store, what kind of professionals do I need to hire in case the App is doing well? As I mentioned I know everything about UI/UX design of the app but by no means I know about programing or how to admin the app. Thank you.
Asked
Last updated .