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 not yet marked as solved
1 Replies
282 Views
Since 12.2, network preferences does not return VPN connections anymore. Therefore, VPN autoconnect scripts / Applications do not work anymore. tell application "System Events" tell current location of network preferences name of every service end tell end tell Returns: {"USB 10/100/1000 LAN", "WLAN", "iPhone-USB", "Thunderbolt Bridge"} Has the API changed?
Posted
by robert.o..
Last updated
.
Post marked as solved
1 Replies
1.1k Views
So I am using shortcuts app on MacOS Monterey. When try to run an AppleScript with Keystroke command in it I get an error message that says "System Events got an error: Shortcuts is not allowed to send keystrokes." Even I gave all the permission to Shortcuts app in privacy settings. Is there any other way to do that in Shortcuts app?
Posted Last updated
.
Post marked as solved
4 Replies
368 Views
My AppleScript applet is localized for French, German, Italian and Spanish. The applet displays text in the correct language if the preferred language is changed in the "General" pane of the Language & Region preferences. That is, the applet correctly works in all four languages. However, the "Apps" pane shows Spanish, German and Italian but, does not show French. For example: Why would the "Apps" pane not show all languages for which the applet is localized ? Thanks late 2015 iMac 27", macOS 12.2.1
Posted
by Crudgle.
Last updated
.
Post not yet marked as solved
1 Replies
187 Views
The following script contains an error that appears when I compile it. Any help would be appreciated. Returns a link to the first selected Apple Mail message *) tell application "Mail" set _msgs to selected messages of message viewer 0 if (_msgs is not equal to missing value) then set _msg to first item of _msgs set _msgID to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & (message id of _msg) return "message://%3C" & (_msgID) & "%3E" end if end tell Many thanks ahead of time.
Posted
by Polyvox.
Last updated
.
Post marked as solved
1 Replies
237 Views
AppleScript's Scripting Additions dictionary contains a number of useful dialogs (e.g. "display dialog", "choose file", "choose from list"). As with most dialogs, the user can cancel and go on with something else. But, when the user presses the "Cancel" button or presses the "esc" key, the dialog returns an error -128. Why is it so ? This can be controlled with some dialogs by defining the buttons to be e.g. "No" and "Yes". The AppleScript code can then respond appropriately to the "No". That avoids the issue but at least, then, there is no need to put the "display dialog" into a try block. But, the buttons on some dialogs cannot be customised e.g. "choose file name". So, every time those dialogs are used, they must be wrapped in a try block so that the script can deal with the user's cancelling of the dialog. Instead, why not return a "Cancel" or a boolean "false" ? If the user presses the "Cancel" button why not return something to indicate that instead of banging an error that has to be trapped ? For example for display dialog it could be {button returned:"Cancel", gave up:false} and for choose file it would be [missing]. I guess that changing this after so many years of people crafting scripts around it would be risky. But, why do those dialogs have to return an error ?
Posted
by Crudgle.
Last updated
.
Post not yet marked as solved
5 Replies
3.4k Views
Anyone had issues with running scripts on Big Sur? I get a command not found error and I’m guessing its a toggle or a command or a back age that needs to be added to enable it or its blocked by default for security reasons?
Posted
by pinni74.
Last updated
.
Post not yet marked as solved
0 Replies
196 Views
Hello, I created a small Apple Script that displays a dialog window containing a reminder message. set theDialogText to "PLEASE TURN OFF THE UPS AFTER COMPUTER SHUTDOWN!!" display dialog theDialogText with title "!!!!!!WARNING!!!!!!" Is there a way to make this dialog window appear before the shutdown of my mac mini M1 (Monterey 12.2.1)? On the bind of the shutdown button for example? The user must click on the dialog window OK button to confirm that he has seen the message. Thank you
Posted
by pixelight.
Last updated
.
Post not yet marked as solved
1 Replies
203 Views
Good evening everyone. I can't run a line of JavaScript in AppleScript. Is that normal? It's normal? Thank you in advance.
Posted
by manuel13.
Last updated
.
Post not yet marked as solved
0 Replies
168 Views
Hello everyone. I created a program that uses "System Events" and I have lots of error messages when it "runs". Two error messages 1): "is not allowed to send keystrokes." and 2): "is not allowed to send keystrokes", is displayed when the program uses "keystrokes" or "key code" with "System Events". I have authorized the AppleScript program in the "Security and Privacy" section and error messages always appear. How to solve this problem? Thank you in advance.
Posted
by manuel13.
Last updated
.
Post not yet marked as solved
0 Replies
160 Views
Hi, I am new here and new to applescripts. Possibly I am in the totally wrong place. However, I figured I would start here. I am interested in making an AppleScript that will: upon creation of an event, duplicate it, name it, and move it to a different calendar. Breakdown: Create Event A under Calendar A Script would execute the following: Duplicate Event A as Event B Move Event B to Calendar B Rename the Event "Busy" Is this possible? Thank you in advance. Joeartist
Posted
by Joeartist.
Last updated
.
Post not yet marked as solved
4 Replies
388 Views
I have a workflow which is installed as a Service. It is used to call code in my AppleScript applet. The Service has one action: a "Run AppleScript" action. I update the Service quite often with improvements. I need a way to know whether my users' copy of the Service is out-of-date. I have developed some ideas: First is to compare file size of user's copy against the copy being distributed. If they are different, then, the user's copy is out-of-date and needs to be updated. That works except that users need to be able to retain changes to their copy of the Service which should not be over-written my by applet. Second is to make a custom property in the workflow's info.plist file. That, however, is over-written by Automator when it saves the workflow. Third is to add a comment to the AppleScript code inside the workflow which can be interrogated by my applet. That does work but, opening and reading the workflow file seems like over-kill and runs the risk of that file being over-written or the XML code being corrupted. Fourth is to add a plain text file to the contents of the workflow which would contain the version detail. My applet could then interrogate that file to get the version and this know whether the user's copy is out-of-date. I'm inclined to using the 4th idea. However, all of those ideas are kludges. Is there an Apple sanctioned method of versioning an Automator service workflow ? Thanks.
Posted
by Crudgle.
Last updated
.
Post not yet marked as solved
0 Replies
116 Views
I would highly appreciate tips and tricks to compile a script which detects different network locations and executes a mount command to my nas. I managed to put a script together that works with a specific network location. I struggle to coming the script with an alternative argument e.g. in addition to my script if network location is set to automatically then do nothing any advice more than welcome THNX
Posted Last updated
.
Post not yet marked as solved
2 Replies
744 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 jrs@adc.
Last updated
.
Post not yet marked as solved
0 Replies
321 Views
Hello, I am trying to copy files using AppleScript(javascript) and for the life of me cannot figure out the correct syntax. I have tried all the possible variations i can think of the following but nothing seems to work. Any suggestions would be greatly appreciated!. var app = Application.currentApplication() app.includeStandardAdditions = true // Tried this app.duplicate("/tmp/file1.txt"), {   to: "/tmp/file2.txt" }) // And all sorts of variations such as app.duplicate(Path("/tmp/file1.txt"), {   to: Path("/tmp/file2.txt") }) // And not including file names app.duplicate("/tmp/file1.txt"), {   to: "/tmp/" })
Posted
by pault604.
Last updated
.
Post not yet marked as solved
0 Replies
306 Views
I use an app to manage my passwords on my Macbook with MacOS Monterey 12.1 and it's suppose to autofill user name and password on website login page. Now with new MacOS I have this message : « Error in system events: Osascript is not allowed to send key entries. (1002)» The full message is this one : « The operation could not be completed. /Users/Phil/Library/Application Scripts/2BUA8C4S2C.com.agilebits.onepassword-osx-helper/ 1Password_Autosubmit.scpt:140:156: execution error : Error in system events : Osascript is not allowed to send key entries. (1002) » Does anyone have an idea about how I can fix this ? Thank you!
Posted
by MrPhilz.
Last updated
.
Post not yet marked as solved
3 Replies
603 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 elsonpeng.
Last updated
.
Post not yet marked as solved
2 Replies
207 Views
Hello everyone. I created a program in Applescript. This program acts directly on the Finder drop-down menu. The program "clicks" in the "Off" menu through the hierarchies click menu item "Turn off" of menu 1 of menu bar item "Apple" via tell "Process Finder" of the "System Events" application. When I run the application, a message: "Direct access not available" appears in error. I installed the "Accessibility" authorization of System Preferences but it doesn't help. The curious thing is when I run this program by being a simple script (by clicking on the Execute script arrow) the operation takes place correctly without error. I searched the internet everywhere but to no avail. It's beyond me. Can you help me?
Posted
by manuel13.
Last updated
.
Post not yet marked as solved
2 Replies
270 Views
For years I've written AppleScript scripts and apps. Seems lately Mac has locked down what you can share and I'm tired of the prompts wether I want to run an AppleScript app or script. In Script Editor on export (File > Export...) there is an option to Code Sign but in Certificates, Identifiers & Profiles what is the correct certificate that I should use to Code Sign my AppleScript app if I plan on distribution? I've searched the docs but I'm not finding an answer. To clarify also I'd like to possibly sell the application on the App Store. If that is not allowed and I can still Code Sign I thought about GumRoad. So that leads to my next question. Are AppleScript applications written in Script Editor allowed to be sold on the App Store? I do have an Apple Developer account.
Posted Last updated
.
Post not yet marked as solved
4 Replies
410 Views
I'm writing an app for the macOS App Store in C++/QT with now some mixed in Objective C, and I'm currently trying to add the following functionality : Create an album in the Apple Photos app, then add some videos to it given their id (videos that are already in the library, not importing videos). For this, I've written the hybrid C++/Objective C function: char *Obj_C::obj_C_addMediaToAlbum(char *albumName, char *mediaId) { NSString *objAlbumName = [NSString stringWithUTF8String: albumName]; NSString *mediaIdS = [NSString stringWithUTF8String: mediaId]; NSString *source = [NSString stringWithFormat:@"tell application \"Photos\"\n" @" set selMedia to (get media items whose id contains \"%@\")\n" @" if not (album \"Trash from %@\" exists) then\n" @" make new album named \"Trash from %@\"\n" @" end if\n" @" add selMedia to album \"Trash from %@\"\n" @"end tell", mediaIdS, objAlbumName, objAlbumName, objAlbumName]; NSDictionary *errorDictionary; NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source]; NSAppleEventDescriptor *resultDesc = [script executeAndReturnError:&errorDictionary]; NSString *returnString = @OBJ_C_SUCCESS_STRING; if ( resultDesc ) { // was successful return (char *)[returnString UTF8String]; } else{ returnString = [NSString stringWithFormat:@"%@", errorDictionary]; return (char *)[returnString UTF8String]; } } I've added the following elements to my entitlements file, after looking at the Photos.sdef file which describes the scripting targets available for the Photos app: <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.automation.apple-events</key> <true/> <key>com.apple.security.scripting-targets</key> <dict> <key>com.apple.Photos</key> <array> <string>com.apple.Photos.library.read-write</string> <string>com.apple.Photos.spotlight</string> </array> </dict> </dict> </plist> And the following to my .plist file as I read somewhere it's necessary: <key>NSAppleEventsUsageDescription</key> <string>The app uses events to control Apple Photos, to help you identify duplicates within you library.</string> When I run this outside the sandbox, it runs fine. However, if I attempt inside the sandbox, I get the error AppleEvents/sandbox: Returning errAEPrivilegeError/-10004 and denying dispatch of event core/getd from process '<private>'/0x0-0x130f30e, pid=63826, because it is not entitled to send an AppleEvent to this process. when looking in the console and the output from my function is : { NSAppleScriptErrorAppName = Photos; NSAppleScriptErrorBriefMessage = "A privilege violation occurred."; NSAppleScriptErrorMessage = "Photos got an error: A privilege violation occurred."; NSAppleScriptErrorNumber = "-10004"; NSAppleScriptErrorRange = "NSRange: {51, 68}"; } I also get the same error if instead of the whole complex AppScript command, I only give the command : "tell application \"Photos\" to make new album named \"Test album\", so it doesn't seem to come from one element of the script itself. **I don't understand: what am I missing to make it work correctly ? ** NB: If instead I use com.apple.security.temporary-exception.apple-events with my entitlements file being : <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.automation.apple-events</key> <true/> <key>com.apple.security.temporary-exception.apple-events</key> <array> <string>com.apple.Photos</string> </array> </dict> </plist> It then works, but it doesn't seem the safe way to do it nor the approved way to do it from my understanding of the temporary exception being intended to be replaced by the scripting targets when available, and they are available for the Photos app...
Posted
by Zyfihx.
Last updated
.