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
2 Replies
396 Views
Code Example I am trying to call an AppleScript application from a Java program. I found this code example: package com.devdaily.mac.applescript; import java.io.IOException; public class MultilineAppleScriptTest { public static void main(String[] args) { new MultilineAppleScriptTest(); } public MultilineAppleScriptTest() { Runtime runtime = Runtime.getRuntime(); // an applescript command that is multiple lines long. // just create a java string, and remember the newline characters. String applescriptCommand = "tell app \"iTunes\"\n" + "activate\n" + "set sound volume to 40\n" + "set EQ enabled to true\n" + "play\n" + "end tell"; String[] args = { "osascript", "-e", applescriptCommand }; try { Process process = runtime.exec(args); } catch (IOException e) { e.printStackTrace(); } } } Problem When searching for the package "com.devdaily.mac.applescript" it references in Eclipse for installing new software, it does not find the package or even just searching for "applescript" in general. So, this must be a one off custom package the author created. Any ideas on locating this package OR do you know of any other examples I can try that performs a similar purpose? Thank you!
Posted
by
Post not yet marked as solved
0 Replies
251 Views
My AppleScript applet provides a GUI for a Python script. A new version of the Python script requires Python3. That means I need to include a Python3 runtime with my applet (or provide a way for users to install). I know almost nothing about Python. How can I create a Python3 runtime for users ? What is in a Python runtime for users ? Must the runtime be in my applet's bundle or must it be installed somewhere ? Must the runtime include all the developer tools that come with Python (e.g. IDLE) ?
Posted
by
Post not yet marked as solved
4 Replies
734 Views
Trying to generate an AppleScript executable for MacOS using Xcode 13 Applescript framework. Right out of the box, the project generated by Xcode has the following difficulty. As shown in the Connections inspector for the "App Delegate" icon, the "App Delegate" does not refer to the AppDelegate.applescript listed in the Project navigator. This results in the inability to connect UI elements to the AppleScript code. A screenshot of the Connections inspector is attached showing the error "AppDelegate does not have an outlet named theWindow" whereas the script clearly defines such an outlet. This project is freshly generated, no changes have been made. Am I missing a configuration piece or something else? Examples I've watched on YouTube of generating simple "Hello World" apps all work as the Xcode IB does normally i.e., by using control-drag to contact different objects, but they were all done on earlier versions of Xcode.
Post not yet marked as solved
1 Replies
252 Views
Looking for a simple AppleScript example of creating an array of string items (i.e. Item 0, Item 1, ... Item n) in a new plist file. Only have found an example of how to read an array item in an existing plist file and not the initial creation of the array of strings itself in a new property list. Appreciate the assistance.
Posted
by
Post not yet marked as solved
0 Replies
199 Views
I have been searching the internet and can't seem to understand how to make this work. I have 150 computers with all different users and passwords. I wanted to create a script that will let me enter the computer name and it will give me a dialog box with the user name and password that corresponds to the computer name entered. I get to the point where I can have it ask for a computer name but I need it to give me info based on different answers. Is that part of variables or strings? If there is a tutorial that better explains this I would love it.
Posted
by
Post marked as solved
3 Replies
343 Views
Hi, how do I use templates in script editor for simple stuff like dialog and text displays and clauses and conditions like if, then, else? Please help.
Posted
by
Post not yet marked as solved
2 Replies
329 Views
Hi, how do i short cut key to access example scripts for script editor? I know how to access the folder but I remember a much more easier way of using a shortcut key to access it which I cant remember.
Posted
by
Post not yet marked as solved
2 Replies
1.1k Views
I have simple script to turn down the brightness of my MacBook Pro via an AppleScript. This worked fine in BigSur, but has stopped working after I upgraded to Monterey 12.0.1. The script is as follows: tell application "System Preferences" reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays" end tell tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display" set value of value indicator 1 of slider 1 of tab group 1 to 0.0 end tell ..error is as follows in script editor: error "System Events got an error: Can’t set window \"Built-in Retina Display\" of process \"System Preferences\" to 0.0." number -10006 from window "Built-in Retina Display" of process "System Preferences" Any suggestions on what to modify to get it working again?
Posted
by
Post not yet marked as solved
2 Replies
559 Views
I have a Java program that I run in Eclipse which executes AppleScript for certain tasks. It works fine in Mojave, but in Big Sur, the AppleScripts fail with the error "AppleScript Not authorized to send Apple events to [app] (-1743)" In Mojave, the user is prompted (one time on the first run) with "'Eclipse.app' wants access to control '[app being controlled by Applescript]'" Once this prompt is approved, then Eclipse is added in the System Preferences under Security & Privacy -> Privacy -> Automation and a checkbox is included and activate for each of the applications that the AppleScript manipulates (Finder and iTunes or Music app depending on OS version), and thereafter,  my Java program can run its AppleScripts. In Big Sur, the prompts never appear and the AppleScript immediately errors out. Furthermore, I see no way to manually add approvals under System Preferences -> Security & Privacy -> Privacy -> Automation and there is no way I can find for how I can approve this automation on my own Mac. How do I invoke AppleScript on Big Sur from other languages such as Java? Please note that the Java program constructs AppleScript content at run time dependent on data, so the scripts are not fixed.  The Java code to run a script goes like this....   String script = <Some expression to form the content of the script depending on data>; String[] myargs = { "osascript", "-e", script}; try {     Process process = runtime.exec(myargs);     process.waitFor(); // Wait for the script to complete.     if (process.exitValue() == 0) { // Success       //On Mojave, execution takes this path and //Applescript works, after the one time user //approval.         System.out.println("success");     } else { // Fail         //On Big Sur, executions takes this path and //outputs         //35:57: execution error: Not authorized to send //Apple events to Finder. (-1743)         InputStream is = process.getErrorStream();       final BufferedReader reader = new BufferedReader(new InputStreamReader(is));         String line = null;         while ((line = reader.readLine()) != null) {             System.out.println(line);         }         reader.close();     } } catch (Exception exc) {     System.out.println(exc.getMessage());    } Thanks in advance for any help!
Posted
by
Post not yet marked as solved
4 Replies
852 Views
I've been searching for this for a few days now and haven't been able to find an answer. I use BetterTouchTool to customize my touchbar, and I've added an action that will love a song in Apple Music like so: if is_app_running "Music" then tell application "Music" try if current track is loved then return "loved" else return "love" end if on error return "" end try end tell else return "" end if end tell This works, but I realized that having a Smart Playlist of Loved songs means nothing if the songs aren't also in your Library. So, I tried figuring out how to also add songs to my Library when they're loved. I tried this: try duplicate current track to playlist "Library" on error duplicate current track to source "Library" end try end tell And it worked sometimes. I had to have the two versions in there for playlist and source because I found one worked for the auto-generated playlists Apple Music makes (like the "New For You" weekly playlist) versus songs from albums or your radio playlist. This is very unreliable. Sometimes it works, sometimes it doesn't. Honestly, most times it doesn't. It's hard to find any real documentation on how to work with Apple Music with AppleScript. I've gone through the Window -> Library view in the Script Editor and can see the list of possible actions and objects, but there's no direction on how they interact. For example, I would think you could simple do add current track to library playlist but that doesn't work at all. Any time I've tried using add with a track, I get an error that the track "doesn't understand the 'add' message". Is there a simple, consistent way to add songs to my Library through AppleScript? Maybe bonus points if it's an add instead of a duplicate? If I manually click and add a song to my Library, it's simple added – but with this AppleScript, I have to duplicate it instead of simply adding. Any help would be appreciated!
Posted
by
Post not yet marked as solved
0 Replies
296 Views
Hoping someone can help with this – I'm running macOS Monterey on an Apple M1 Pro laptop. My AppleScript to send out batch text messages, stored on an Excel file, delivered through the Messages app is now not working – it worked fine on my old laptop operating under Catalina. The problem appears to be in delivering the phone number ("targetBuddyPhone") into the proper location in the Messages app. Instead, the text message ("targetMessage") is being dropped into the recipient location in the app. Does anyone have any ideas on possible solutions? Thanks in advance. set phoneCol to "B" set messageCol to "C" set startRow to 1 set counter to "D" set xlsFilePath to (path to desktop as text) & "texttest.xlsx" tell application "Microsoft Excel" to open file xlsFilePath tell application "Microsoft Excel" set endRow to value of cell (counter & startRow) as number end tell repeat with thisRow from startRow to endRow tell application "Microsoft Excel" set targetBuddyPhone to string value of cell (phoneCol & thisRow) as string set targetMessage to value of cell (messageCol & thisRow) as string end tell activate application "Messages" tell application "System Events" to tell process "Messages" key code 45 using command down -- press Command + N to start a new window keystroke targetBuddyPhone -- input the phone number key code 36 -- press Enter to focus on the message area delay 3 keystroke targetMessage -- type some message key code 36 -- press Enter to send end tell delay 6 end repeat return input end run
Posted
by
Post marked as solved
1 Replies
315 Views
Hi All, first post, so be kind please. :) Goal is to get a series of trivia keynote decks generated with solely info from a numbers table. Getting Error -1700: Can't convert types. Can anyone at a basic level tell me what this means? I'm fine with building the rest of the code myself, I just don't understand this portion. Thanks. Create New Slides from Table
Posted
by
Post not yet marked as solved
1 Replies
286 Views
I have the following code inside a python file: applescript.run(''' tell application "System Events" -- one second delay delay 1 -- to press command+shift+g keystroke "G" using {command down, shift down} delay 2 -- to enter file path keystroke "/Users/***/Documents/web_images/image_1.jpg" delay 1 -- hit return twice keystroke return delay 1 keystroke return end tell ''') It was working great until I installed Monterey, now it's not working anymore. Anyone any idea how to fix it?
Posted
by
Post marked as solved
1 Replies
238 Views
Hi everyone, since weeks I am getting a lot of spam via email, these emails are all different but what they have in common is a hyperlink. Since Apple mail doesn't allow you to create a rule based on raw source but only on body content, I am trying to create a rule that copies the entire message, convert it to string, check if a specific string is in it and then deletes the message. my entire script is ready but I am having difficulties on converting "theMessage" into string, I guess that the html code is somehow sending AppleScript crazy. Do you have any suggestion?
Posted
by
Post not yet marked as solved
0 Replies
158 Views
I am currently in the process of trying to deskew some antique prints, around 10,000 images. I have pretty well figured out how to automate the rest, as novice as it may be, but I am stuck on deskewing and centering the photos. Due to the age, the various aspects are never uniformly angled, so all the options I have found have a 10% chance of straightening successfully. Ideally, the app would display each photo, allow me to define a line to rotate to 90degrees, or an angle measurement tool to subtract that angle from the original angle, and move to the next photo in a que. Deskewing the photo is the priority, but, it would be nice to be able to define a centerline to re-center the photo as well. Thanks
Post not yet marked as solved
0 Replies
180 Views
I am trying to use AppleScript to set the formula of a cell in Microsoft Excel. I am running into an error but I don't have enough AppleScript knowledge to understand or fix the error and need some help. It seems to be treating part of the formula as a variable. It stops at the word History, colored in green and mentions the variable can't be made into real type in the error. I want the entire string to be treated as text it inserts into the cell. I realized I needed to escape the quotes but it is still not working. I think there is a problem with the commas and the quotes too. Any help would be appreciated! Tell application "Microsoft Excel" tell active sheet set formula of range "E2" of active sheet to "=IF(J2=/" & History /" & ,  /" & level2 / ",IF(ISNUMBER(SEARCH(/" & ICU / “,level2)),/“ & ICU / ", /" & level3 / "))" end tell end tell
Posted
by
Post not yet marked as solved
0 Replies
203 Views
Hi everyone, I have a MacBook Air M1 (that doesn't have the function keys for increasing and decreasing the backlight of the keyboard). I'm searching to manage the luminosity of the keyboard from the keyboard. I would not to re-map some keys, so I thought to create an Apple script and link it to a keyboard shortcut with the shortcut app. The problem is that I don't know the apple script language so I'm here to ask some help to write it or to suggest me other options. Thank everyone that will help me.
Posted
by
Post not yet marked as solved
2 Replies
539 Views
Until Big Sur I was asking the administrative privileges using the command /usr/bin/osascript -e 'do shell script "ls" with prompt "Installer is trying to setup" with administrator privileges' which gives me this dialog box Now the same command in mac os monetery is giving me the prompt with the title as "osascript". How can I replace the osascript title with my app name. Thanks in advance
Posted
by
Post not yet marked as solved
0 Replies
165 Views
Hi everyone. I am new to AppleScript and while willing to learn and spend the time to figure out how to do it myself, I need this macro built soon. I can imagine it is not terribly difficult for someone with experience. Here is what I would like to accomplish. Copy text into clipboard. (ie I copy "COMPANY XYZ" into clipboard) Run the Applescript Script creates a COMPANY XYZ folder under CUSTOMER folder The end result will be CUSTOMER/COMPANY XYZ. Thank you if anyone has this Applescript or can help me out. :)
Posted
by
Post not yet marked as solved
3 Replies
427 Views
Hi, I'm working on an app based on the ITLibrary so I can get all the tracks info like their persistent ID and I'd like to play it in Music from my app. I do it easily with AppleScript so do I need to use a bridge or can I do it directly from a Swift 4 app ? Thx.
Posted
by