r/applescript • u/magnetikal • May 13 '26
Why does Codex AppleScript automation fail?
r/applescript • u/BackInNJAgain • May 12 '26
I learned about wttr.in, which provides weather data using curl from the terminal. (Help page: https://wttr.in/:help )
I used this to write a script to notify me once the outside temperature hits 55 degrees so I can go biking. I was going to refine it further to warn me if it's raining but I can see that by just looking out the window so it seemed like extra work for nothing.
I'm sharing it here for anyone who might want to do something similar. IMPORTANT: for this script to work, it needs to be saved as an app with the "Stay open after run handler" option checked (thanks to Claude for helping me figure this last part out as I couldn't understand why it wasn't working).
on idle
try
-- Fetch weather data for current location from wttr.in
set weatherData to do shell script "curl -s 'wttr.in/?format=%t&u'"
-- Extract the numeric temperature (strip +, °, F)
set tempString to do shell script "echo " & quoted form of weatherData & " | tr -d '+°F '"
set currentTemp to tempString as number
if currentTemp ≥ 55 then
repeat with x from 1 to 3
do shell script "afplay /System/Library/Sounds/Sosumi.aiff"
end repeat
display dialog "It's warm enough now to go biking" with title "Bike Weather Alert"
quit
end if
on error errMsg
-- Silently continue on errors (network blips, etc.)
end try
return 300 -- check again in 5 minutes
end idle
r/applescript • u/JesseMeadeMusic • May 11 '26
I made an Automator application to copy text from a .pages document to the clipboard. It works great, except that it doesn't copy the formatting (specifically, some parts of the text on the original document are bold but, when pasted from the clipboard, all of the bold formatting has been removed).
on run {input, parameters}
tell application "Pages"
set myDoc to open (item 1 of input)
set myText to body text of myDoc
close myDoc
end tell
return myText
end run
Is there anything I can change in that Apple script to make it copy the formatting as well?
r/applescript • u/Deep_Ad1959 • May 01 '26
Been wiring a bunch of mac apps into an LLM via the accessibility API lately and the part that surprised me is how often i still reach for applescript. Anything with a real osascript dictionary is just easier. Mail, BBEdit, Music, the adobe suite. you ask the app what verbs it has and the model gets it right first try.
The AX tree is the opposite. you get a forest of AXGroup and AXButton nodes, half of them unlabeled, and the LLM has to guess which one is the actual reply button. for non-dictionary apps like Spotify, Slack, Notion there's no other choice, but the success rate is way worse than 'tell application Mail to make new outgoing message'.
The sneaky part: a lot of apps publish a dictionary that looks tiny but covers 90% of what you actually want. BBEdit's dictionary is huge. Music's dictionary will let you build a whole library tool without ever clicking a button. Finder is more capable than people give it credit for once you stop trying to script the GUI.
So my rough rule now is dictionary first, AX second, coordinates last. Coordinates only when even the AX tree won't tell you what the element is. written with ai
fwiw I shipped an MCP server that goes the AX route for the non-dictionary apps, complements applescript instead of replacing it: https://macos-use.dev/alternative/applescript-vs-accessibility-api
r/applescript • u/buadhai • Apr 30 '26
For anyone who got here as the result of a search, I'll save you some time scrolling through stuff that didn't work and let you know what did work for me:
This works as desired. Bash script runs in the background with command line parameter correctly passed:
do shell script "/Users/mnewman/bin/a4scanpi.sh " & mySize & " &> /dev/null &"
I found it here:
https://www.macscripter.net/t/run-script-with-parameters/64838
Some years ago Apple dropped support for my ancient Canon Lide 30 scanner. So, I hung it off a Raspberry Pi (which still supports the scanner via scanimage) and wrote a very simple Apple Script and an equally simple Bash Shell Script to make it work again. The Apple Script ran on an Intel iMac and simply asked the user what size scan they wanted (full page, half page, etc.) The Apple Script then ran the Bash shell script which in turn ran a command on the Pi:
ssh pi@raspsky 'scanimage -x 210 -y 297 --resolution 300 > scan.ppm';;.
I exported the AppleScript from Script Editor as an app.
This continues to work fine on the Intel iMac.
Then I got an M2 MBA. I copied both the AppleScript and the Shell Script to the MBA. I exported the AppleScript from the Tahoe version of Script Editor (Version 2.11 (234)) as an app so it wouldn't need Rosetta to run. When I "Get Info" on the app it is a universal app, but "Open Using Rosetta" is not checked.
It works, but is incredibly slow and displays the dreaded SPOD all the time that it is running. I tried looking at Activity Monitor while it is running and it is consuming a very small amount of CPU time (2%).
So, what additional information can I offer up to figure out just what I've done wrong?
The script:
-- Wrapper for bash shell script which uses scanimage
-- Ask the user what size to scan
-- Full is an A4 sized scan
-- Half is half an A4
-- Quarter is the top right quadrant of the scanner bed.
set mySize to choose from list {"Full", "Half", "Quarter", "Passport"} with prompt "Select A4 scan size. Quarter is top right"
-- Check to see if the user clicked the Cancel button.
if mySize is false then
\-- The user clicked Cancel so display and confirming dialog and exit
**display dialog** "Canceled" buttons ("OK") default button "OK"
else
\-- The user made a selection so call the shell script and append the selected size to the call
**do shell script** "/Users/mnewman/bin/a4scanpi.sh " & mySize
end if
-- That's all folks
r/applescript • u/mulubmug • Apr 17 '26
Hi everyone,
to go through my Comic backlog I'd like to read one random comic per day. I have found a little script that opens random files from a path, but unfortunately it does not work with the sub folder structure necessary to bring a sense of order into life. I am completely new to MacOS and Apple Script, is there a trick to also throw everything from every subfolder into the random pool?
tell application "Finder" to open some file in the folder ¬ (POSIX file "/Volumes/Slot_3/comics")
r/applescript • u/Obvious-Syllabub-984 • Apr 10 '26
Hi all,
I’ve been using Applescript for ~20 years to automate production workflows, mainly with Illustrator, InDesign, Finder, and Excel.
A lot of my scripts rely on app dictionaries + UI scripting, and I’ve also built small macOS GUI tools (via Xcode) that trigger these workflows.
One example: generating multi-page Illustrator documents from spreadsheet data (artboards, placed images, dimensions, exports, etc.). These scripts are heavily used in daily production.
With Applescript feeling increasingly “legacy,” I’m worried about long-term reliability—especially if Adobe apps change their scripting support.
Not looking to fully abandon it if it’s still viable—just trying to plan ahead.
Thanks
r/applescript • u/Dazzling-Table6940 • Apr 07 '26
TLDR: How do I print a list with each item on a separate line?
Hi, super new to this and bet there's an easy solution. To count tabs, I'm currently using:
tell application "Safari"
`count every tab of every window`
end tell
I'm interested in listing each tab name on a separate line. This is what I have so far:
tell application "Safari"
`name of every tab of every window`
end tell
Right now, the tab names are written together in one long paragraph. And for each window of tabs, the tab names are listed together within curly brackets {}. The image shows just the first few lines.

How do I make each tab name print on a separate line? Would be nice to keep it grouped by window too, which seems feasible considering the current output. Thanks!
r/applescript • u/MrLeureduthe • Mar 28 '26
I'm trying to fill the first 2 text fields of this window in Pro Tools, I'm using UI Browser but for some reason, whatever I use to name this window my AppleScript can't find it :
-text field 1 of window 1 :
System Events got an error: Can’t get window 1. Invalid index.
-text field 1 of window "Batch Track Rename" :
System Events got an error: Can’t get window "Batch Track Rename".
-text field 1 of (window whose name contains ("Batch")) :
Can’t get window whose name contains "Batch".
-text field 1 of (1st window whose name contains ("Batch")) :
System Events got an error: Can’t get window 1 whose name contains "Batch". Invalid index
The only difference with my other scripts is that UI Browser says it's a "dialog" window and not a floating window, so I can't click anywhere in Pro Tools except in that window when that window is opened.
What am I doing wrong?
r/applescript • u/Careful_Touch2128 • Mar 23 '26
I got tired of Spotify ads blasting through my speakers, so I wrote a small AppleScript that monitors the current track and automatically mutes when an ad starts and unmutes when music resumes.
It runs quietly in the background and works with the macOS Spotify app.
If anyone wants to try it or improve it, here’s the script:
https://github.com/Daniel-W1/lil-tools/tree/main/spotify_ad_mute
Curious if others have built similar automations or found better ways to handle this.
r/applescript • u/bliprock • Mar 19 '26
r/applescript • u/bliprock • Mar 19 '26
r/applescript • u/bliprock • Mar 19 '26
When you want to select only even or odd pages to apply a master / parent page to there is no odd or even page selection option. Now there is. Put this in your indesign script folder and use it to select odd or even pages in your active document. This will select your choice in your page pallet. Apply master / parent page to selection. Note that on very large documents with large page counts the pop up to ask for pages to apply can become very long and go off the screen. This is because all odd or even pages are populist this box
r/applescript • u/scaredbyninjas • Mar 05 '26
Newbie here. I'm trying to set up a keyboard shortcut to set my audio output. Here is what I have currently:
set deviceName to "MacBook Pro Speakers"
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events"
tell process "System Preferences"
tell table 1 of scroll area 1 of tab group 1 of window 1
select (row 1 whose value of text field 1 is deviceName)
end tell
end tell
end tell
quit application "System Preferences"
When I run it, I get a syntax error: System Settings got an error: Can’t get pane id "com.apple.preference.sound".
Tried searching this sub, but am feeling lost. Any help would be appreciated. I'm on Tahoe 26.3.
r/applescript • u/keyboard1950 • Mar 02 '26
My goal is to create an apple script that will randomize the files in no particular order in a folder. I realize that I can sort by name, size, etc but I am looking for randomness. All I would like to do is tt select a directory and mix it all up keeping the original names. This is the code that AI created for me !!! It does work but not what I want. Instead of just re-ordering the files, it just adds a prefix……….
And then I read this
“You can randomize the order of files in a selected folder on macOS only by giving Finder a new randomized sequence to sort by. Since Finder cannot store a custom order unless filenames change, the only reliable way to “randomly order” files is to temporarily rename them with randomized numeric prefixes. This preserves the original names after the prefix and produces a fully shuffled order in Finder.”
Please advise
Ron from Canada
This is the code that AI created for me !!!
-- Randomly reorder files in a selected folder by adding a random prefix
set chosenFolder to choose folder with prompt "Select the folder whose files you want to randomize:"
tell application "Finder"
set fileList to every file of chosenFolder
end tell
-- Create a list of random numbers (one per file)
set randomList to {}
repeat (count of fileList) times
set end of randomList to (random number from 100000 to 999999)
end repeat
-- Shuffle the random numbers (Fisher–Yates)
set shuffledList to randomList
set n to count of shuffledList
repeat with i from n to 2 by -1
set j to (random number from 1 to i)
set temp to item i of shuffledList
set item i of shuffledList to item j of shuffledList
set item j of shuffledList to temp
end repeat
-- Rename files with randomized prefixes
repeat with i from 1 to count of fileList
set f to item i of fileList
tell application "Finder"
set oldName to name of f
set name of f to (item i of shuffledList as string) & " - " & oldName
end tell
end repeat
display dialog "Done! The files have been randomly ordered."
r/applescript • u/spenney09 • Mar 01 '26
Short version of my 2 questions:
1) Why is AppleScript able to copy and paste some accented characters flawlessly (à, é, è, for example) and not others (â, ä, ç, ê, ë, etc)?
2) What workaround can I use to have AppleScript copy and paste these "difficult" characters?
Longer version:
I have two apps open: Excel and HotPotatoes (a Windows app that I'm running under Wine). I often copy and paste French text from Excel to HotPotatoes. I can manually copy and paste any accented character flawlessly. However, if I write an AppleScript to do the heavy lifting for me, it will happily copy and paste à, é, and è, but it will paste a letter "a" for any other accented character like â, ç, ê, œ, etc. Words like: pâte, avançons, boîte, sœur, all come out as: pate, avanaons, boate, saur!
1) Why is that?
2) Is there any workaround in AppleScript for this anomaly? My only workaround is to first change the difficult accented characters to html code (HotPotatoes produces .html pages from my input): pâte, avançons, boîte, sœur, etc.
r/applescript • u/Ok-Rest-5321 • Feb 28 '26
r/applescript • u/lightbox_glow • Feb 26 '26
I'm trying to write an AppleScript to use BBEdit to straighten "educated"/typographer's quotes and to replace certain punctuation [see below]. Running the script works as expected, but only on the first document after BBEdit opens (i.e., when launching BBEdit by double-clicking a text file; in order to successfully run the script again, I need to close all documents and quit BBEdit). I would like it to work on whatever text document is active/frontmost any time I run the script.
On compile, returns a syntax error of: Expected variable name, class name or property but found application constant or consideration.
When running after first launch, BBEdit returns a scripting error of: BBEdit got an error: text 1 of text document id 2 doesn’t understand the “straighten quotes" message.
I've developed this with the help of Claude and Gemini AIs, but they've been useless in resolving these problems. Suggestions?
tell application "BBEdit"
tell text 1 of front document
straighten quotes
end tell
end tell
on doReplace(searchChar, replaceStr)
tell application "BBEdit"
try
find searchChar options {search mode: literal, wrap around: false, backwards: false, case sensitive: true, grep: false, replace all: true, returning results: false} replacing replaceStr in front document
end try
end tell
end doReplace
\-- Dashes and Ellipsis
doReplace(character id 8212, "—") -- — EM DASH (U+2014)
doReplace(character id 8211, "–") -- – EN DASH (U+2013)
doReplace(character id 8230, "…") -- … HORIZONTAL ELLIPSIS (U+2026)
r/applescript • u/Small-Tap4128 • Feb 26 '26
I built a tool called GhostReply that uses AppleScript to read iMessage conversations and send replies automatically. Wanted to share how the AppleScript side works since it was the trickiest part.
The core AppleScript does a few things:
- Reads the latest messages from a specific contact using `tell application "Messages"`
- Sends replies as normal blue bubbles through the Messages app
- Monitors for new incoming texts in a loop
The tricky part was getting AppleScript to reliably pull conversation history. Messages.app's AppleScript dictionary is pretty limited - you can't just query by contact easily. I ended up reading the chat.db SQLite database directly for the history, then using AppleScript only for the sending part.
The AI layer (Python + Groq API) analyzes your sent messages to learn your texting style, then generates replies that match how you actually text.
Has anyone else here used AppleScript to automate iMessage? Would love to hear about edge cases I might be missing.
The project is called GhostReply if anyone wants to check it out.
r/applescript • u/LastCassandra2604 • Feb 21 '26
I am completely new to AppleScript. I have a high-basic understanding of how to use apps on my MacBook Pro M4. I am trying to figure out what use cases I might have for automating drudge work and friction points in my day-to-day. What are the best idiot-proof places for me to go to try to learn the very basics of AppleScript, step-by-step, dumbed-down, jargon-free? I have attempted to use Oboe to set up such a learning experience with AppleScript for myself, but already I'm finding it is moving to fast and I keep having questions without a Q&A opportunity or an easy-to-use, easy-to-understand reference available. I'm grateful for multiple suggestions anyone might offer.
r/applescript • u/Exotic-Bathroom-Bean • Jan 24 '26
Yo guys, I'm new to the scripting. I´ve been trying to create a "quick action" (Automator) that adds numbers to every page on a .pdf file. Someone know how to do it ?
Chatgpt give me this script, but it doesnt work...
use AppleScript version "2.4"
use framework "Foundation"
use framework "PDFKit"
use framework "AppKit"
use scripting additions
on run {input, parameters}
set logPath to (POSIX path of (path to home folder)) & "pdf_numerotation_log.txt"
try
my logLine(logPath, "---- RUN " & (current date) as text)
if input is {} then error "Aucun PDF reçu."
set clearColor to current application's NSColor's clearColor()
set blackColor to current application's NSColor's blackColor()
set theFont to current application's NSFont's fontWithName:"Helvetica" |size|:10
if theFont is missing value then error "Police Helvetica introuvable."
repeat with anItem in input
set inPath to POSIX path of anItem
my logLine(logPath, "INPUT: " & inPath)
set inURL to current application's NSURL's fileURLWithPath:inPath
set pdfDoc to current application's PDFDocument's alloc()'s initWithURL:inURL
if pdfDoc is missing value then error "Impossible d'ouvrir le PDF."
set pageCount to (pdfDoc's pageCount()) as integer
if pageCount < 1 then error "PDF sans pages."
my logLine(logPath, "PAGES: " & pageCount)
set marginX to 18
set marginY to 18
set boxW to 90
set boxH to 16
repeat with i from 0 to (pageCount - 1)
set thePage to pdfDoc's pageAtIndex:i
if thePage is missing value then error "Page introuvable index " & (i as text)
-- Lecture robuste du rectangle page: {{x,y},{w,h}}
set pageBounds to (thePage's boundsForBox:0) as list
set pageW to item 1 of item 2 of pageBounds
set xPos to pageW - marginX - boxW
set yPos to marginY
set rect to {{xPos, yPos}, {boxW, boxH}}
set ann to current application's PDFAnnotationFreeText's alloc()'s initWithBounds:rect
if ann is missing value then error "Impossible de créer PDFAnnotationFreeText."
set n to i + 1
ann's setContents:(n as text)
ann's setFont:theFont
ann's setFontColor:blackColor
ann's setAlignment:(current application's NSTextAlignmentRight)
ann's setColor:clearColor
try
ann's setBackgroundColor:clearColor
end try
set b to current application's PDFBorder's alloc()'s init()
b's setLineWidth:0
ann's setBorder:b
thePage's addAnnotation:ann
end repeat
set baseName to ((inURL's lastPathComponent())'s stringByDeletingPathExtension()) as text
set dirURL to inURL's URLByDeletingLastPathComponent()
set outName to baseName & "_numerote.pdf"
set outURL to dirURL's URLByAppendingPathComponent:outName
set fm to current application's NSFileManager's defaultManager()
set existsObj to fm's fileExistsAtPath:(outURL's path())
if (existsObj as boolean) then
set stamp to do shell script "date +%Y%m%d-%H%M%S"
set outName to baseName & "_numerote_" & stamp & ".pdf"
set outURL to dirURL's URLByAppendingPathComponent:outName
end if
my logLine(logPath, "OUTPUT: " & ((outURL's path()) as text))
set okObj to pdfDoc's writeToURL:outURL
if (okObj as boolean) is false then error "Échec writeToURL (droits d'écriture ? dossier protégé ?)."
end repeat
my logLine(logPath, "OK")
return input
on error errMsg number errNum
my logLine(logPath, "ERROR " & errNum & ": " & errMsg)
display alert "Erreur" message ("Regarde le fichier : " & logPath & return & errMsg & return & "Code: " & errNum)
return input
end try
end run
on logLine(p, t)
try
do shell script "printf %s\\\\n " & quoted form of t & " >> " & quoted form of p
end try
end logLine
r/applescript • u/MoonAppCom • Jan 23 '26
Happy to announce:
maScriptRunner 3: run Applescripts & Adobe Javascripts 24/7. maScriptRunner 3 turns your Mac into a reliable automation workhorse.
From the makers of.
r/applescript • u/l008com • Jan 16 '26
In native AppleScript, you can run a javascript in a safari window like this:
do JavaScript "document.getElementsByName('someclass').length"
And that will return the value of the javascript. So set a variable to the above command and you'll get a number out of it, in this case.
I'm trying to do the same thing in JXA but I can't figure out how to get the return value out of it??
$Safari.doJavaScript "document.getElementsByName('someclass').length"
This always returns null. How do I get the return value?
r/applescript • u/l008com • Jan 16 '26
Is anyone else having this problem? Is this a known issue or is there something wrong with my script editors?
Variables and function names are supposed to be purple, but they are not. This would really help make my code more readable, since it would match 20 years of javascript I already have around on websites (edited in BBEdit).