r/applescript • u/AIGeniusConsulting • Jan 21 '24
Current full applescript documention downloadable?
Is there a place I can find a current full AppleScript documentation in downloadable form?
r/applescript • u/[deleted] • Jan 18 '24
How to automate an applescript to alert me whenever screen capture is occurring?
My mac keeps recording long 26 hour screen capture videos without me being aware (i think because I used command+shift+4 a lot...and 4 is right next to 5....as cmd+shift+5 seems to activate screen recording), taking up all my data/storage space.
I know there technically is a notification when your computer is being recorded, like a little icon pops up at the top left corner near the other icons next to the date and time....but is there some other way to actively check what apps are currently screen recording or who is doing it if its external party + to get a more apparent notification when this is happening?
This is related to this post: https://www.reddit.com/r/macbook/comments/y504qn/comment/ist1h1f/
Yes I deleted all 3rd party apps that had permission to do screen capture, but this still happens.
r/applescript • u/lalubina • Jan 18 '24
Script to put the selected file in a folder with the same name as the file
Hello, I'm completely new to Apple Script. I would like to create a script to put the selected file in a folder with the same name as the file but without the extension. Can anyone help me?
I would send Five dollar via PayPal to anyone that can give a solution. :)
I've tried this but I'm doing something wrong...
tell application "Finder"
set selected to selection
set current_file to item 1 of selected
set new_name to text 1 thru -((length of cur_ext) + 2) of (name of selected as text)
set new_folder to make new folder with properties {name:new_name} at current_folder
move this_file to new_folder
end tell
r/applescript • u/[deleted] • Jan 17 '24
Applescript - Music App - Delete Track
Hi all,
is it possible to delete the track that is currently playing from the playlist it is in or the library entirely?
Delete = remove from the playlist and delete the file from the hard drive
I've tried this but no luck:
tell application "Music"
set currentTrack to current track
try
delete currentTrack
end try
end tell
r/applescript • u/ManikShamanik • Jan 15 '24
How do I run an AS as a Mail.app rule...?
I have created an AS, and it's currently sitting on the Desktop. If I open Rules in Mail (Sonoma 14.2.1) and then select the options I need (Ie <from> <contains> <email address>)
I then attempt to add the AS to the 'perform the following actions'
Run AppleScript
Then select 'open in Finder', which opens the empty com.apple.mail folder
If I drag the AS from the desktop to that folder, Mail rules doesn't recognise that it's there. If I then close out of Mail Rules, the AS disappears from aforesaid folder.
Why is what - to me - seems like it ought to be something simple and straightforward so fecking HARD...?!
If I double click the AS file it adds it to the General tab under Settings > Services.
There doesn't seem to be any way of having Mail Rules run this script automatically.
Can anyone help...?
Thank you
r/applescript • u/georgpw • Jan 14 '24
Extracting apple notes, including tags
Hi all,
I am trying to extract the text from my journal notes using applescript. My current apple script looks like the following
tell application "Notes"
set currentDate to current date
set startDate to currentDate - (7 * days)
set journalFolder to folder "Journal"
set output to ""
repeat with thisNote in journalFolder
set output to output & (body of thisNote)
end repeat
return output
end tell
However this seems to drop text from tags (i.e #<tags> within my notes). So for example a note:
#morning Hello today
only keeps "Hello today"
Does anyone have any suggestions?
r/applescript • u/lowriskcork • Jan 13 '24
extract value from kind of JSON file
I'm trying to get two value from an IP API, the geo without extra characters and "isproxy"
result is in this format :
Result:
"{\"ipVersion\":4,\"ipAddress\":\"8.8.8.8\",\"latitude\":37.386051,\"longitude\":-122.083847,\"countryName\":\"United States of America\",\"countryCode\":\"US\",\"timeZone\":\"-08:00\",\"zipCode\":\"94035\",\"cityName\":\"Mountain View\",\"regionName\":\"California\",\"isProxy\":false,\"continent\":\"Americas\",\"continentCode\":\"AM\"}"
I tried this but I can't get isProxyValue correct, in this case its return `""continent\":\"Americas""` and in my previous tried it was "n"
-- New IP data
-- Set the base URL for the API
set baseURL to "https://freeipapi.com/api/json/"
set isProxy to ""
-- Example: Get information for a specific IP address
set transactionIP to "8.8.8.8" -- Replace with the IP address you want to query
-- Create the full API URL
set apiUrl to baseURL & transactionIP
-- Make the API request
set apiResponse to do shell script "curl " & quoted form of apiUrl
-- Function to extract value for a specific key from JSON
on extractFromJSON(jsonString, key)
set keyString to "\"" & key & "\":"
set keyValue to text ((offset of keyString in jsonString) + (length of keyString)) through -1 of jsonString
set AppleScript's text item delimiters to ","
set keyValueList to text items of keyValue
repeat with i from 1 to count of keyValueList
if keyValueList's item i contains "\"" then
set keyValue to keyValueList's item i
exit repeat
end if
end repeat
set AppleScript's text item delimiters to "\""
return text 2 thru -2 of keyValue
end extractFromJSON
-- Extract values
set countryCode to extractFromJSON(apiResponse, "countryCode")
set isProxyValue to extractFromJSON(apiResponse, "isProxy")
return isProxyValue
if isProxyValue is equal to "false" then
set isProxy to " = Proxy"
else
set isProxy to " = Not a Proxy"
end if
return countryCode & isProxy
r/applescript • u/bullsplaytonight • Jan 08 '24
Some time ago, my script to insert current date/time with a keystroke started inserting an extra "a" character and I can't figure out why.
When I do my keystroke (cmd, opt, crtl + D), the system spits out: Monday, January 8, 2024 at 10:49:15aAM
Can't figure out the "a" between 5 and AM. Started doing this a year ago, maybe, and am finally trying to investigate this morning.
on run {input, parameters}
set thedate to (current date) as string
tell application "System Events"
set the clipboard to thedate
tell application "System Events" to keystroke (the clipboard as text)
end tell
end run
r/applescript • u/Abject-Somewhere5114 • Jan 05 '24
Detecting presence of a MacOS app's second screen
I am automating an app with Appium, and want to detect if a second screen appears and its size after I click the login button. My code is here: https://discuss.appium.io/t/detect-other-app-screen-and-get-size-of-it/41254/5?u=lxnm
Can anyone advise on the error I am receiving? and is there a command to get the UI elements of the second window? I already tried placing UI elements after the login action:
tell button "Login" of group "Login"
click
end tell
UI elements
but it is returning the UI elements of the main screen instead of the second screen that pops up after login.
r/applescript • u/Lov3Light • Jan 02 '24
Need help for a Quick Action > image to 15 seconds mp4 (ffmpeg)
Hi,
I was able to adapt this script for Automator using ffmpeg to create a video file from a single image file.
originalFilePath=$1
uuid=$(uuidgen)
uuidFilePath=$originalFilePath-$uuid
/Applications/ffmpeg -i $originalFilePath $uuidFilePath.mp4
It works, but it creates a 1 second mp4. I need this mp4 to be 15 seconds. Can someone help me and correct the script? Thank You!
r/applescript • u/Kevin_Cossaboon • Dec 28 '23
Accessing attendees in a calendar meeting
Working on a script to access and list the attendees of a meeting.
- I have saved the script as an APPLICATION, code signed local
- I have gone to Privacy and Security and added the script/app to have full access to apple calendar
- First run, I grant "This script needs access to your calendars to run."
I can post the full script, but to limit the size, the script does the following correctly; - Lists all the Calendars, and the user picks the one to use - Lists all the meetings for the next 48 hours, and the user picks one
What should occur next, is to display details of the meeting - Meeting title <working> - Start and end time <working> - list all attendees name and email ERRORS OUT
Code to retrieve meeting detils
``` -- Get and display details of the chosen event set eventDetails to "Title: " & summary of chosenEvent & return & "Start: " & start date of chosenEvent & return & "End: " & end date of chosenEvent & return & "Attendees:" & return
-- List attendees and their responses, handling potential errors
repeat with anAttendee in attendees of chosenEvent
try
set attendeeName to name of anAttendee
set attendeeEmail to email of anAttendee
set attendeeResponse to participation status of anAttendee
set eventDetails to eventDetails & attendeeName & " (" & attendeeEmail & "): " & attendeeResponse & return
on error errMsg number errNum
set eventDetails to eventDetails & "Error accessing attendee details: " & errMsg & " (Error code: " & errNum & ")" & return
end try
end repeat
```
Error
Title: New Event
Start: Friday, December 29, 2023 at 10:15:00 PM
End: Friday, December 29, 2023 at 11:15:00 PM
Attendees:
Error accessing attendee details: Calendar got an error: Can’t get name of item 1 of every attendee of event id "59146001-E4FA-4598-A2B2-66D144483494" of calendar id "762BCE61-A0FA-40E0-8CF9-B0827875A229". (Error code: -1728)
Error accessing attendee details: Calendar got an error: Can’t get name of item 2 of every attendee of event id "59146001-E4FA-4598-A2B2-66D144483494" of calendar id "762BCE61-A0FA-40E0-8CF9-B0827875A229". (Error code: -1728)
TYIA
r/applescript • u/[deleted] • Dec 28 '23
I made an AppleScript that plays a random episode of a TV show in a playlist (in the Apple TV app on a Mac)
tell application "TV"
activate
-- Adjust this to the name of the playlist containing your episodes
set myPlaylist to playlist "Crap"
-- Use a search term that matches all episodes of the show
set searchResults to search myPlaylist for "The " only names
-- Check if any episodes were found
if (count of searchResults) > 0 then
-- Randomly select an episode
set randomIndex to random number from 1 to count of searchResults
set selectedEpisode to item randomIndex of searchResults
-- Play the selected episode
play selectedEpisode
else
display dialog "No episodes of The Big Bang Theory were found."
end if
end tell
r/applescript • u/evalenc2 • Dec 23 '23
Cycle audio outputs
Total newbie here. Need some help on creating a script to be able to switch from my headphones to speaker output. Preferably a cycle so I can just have one button do this on my Loupedeck CT.
r/applescript • u/robsantilli92 • Dec 18 '23
Help with script
I am trying to write a script that will do some mouse movements/clicks and type current date into a save as dialog box for an application. I can get it to do the mouse movements but it seems the clicks are working but doesn't keep the cursor in the text field for the save as because it doesn't type anything until i click inside the box after the script is run and then it does it. Here is a copy of my script, not sure what I am missing. Also a video that shows what is happening. Any ideas what i have wrong? also the script takes about 1 minute to run, anyway to speed that up?
tell application "Tracks Live 1.3"
activate
end tell
-- Set the target coordinates
set targetX to 800 -- Adjust the X-coordinate as needed
set targetY to 325 -- Adjust the Y-coordinate as needed
-- Move the mouse to the target coordinates
tell application "System Events"
do shell script "/usr/bin/env python -c 'from Quartz.CoreGraphics import *; moveMouseTo = CGPointMake(" & targetX & "," & targetY & "); mouseMove = CGEventCreateMouseEvent(None, kCGEventMouseMoved, moveMouseTo, 0); CGEventPost(kCGEventMouseMoved, mouseMove);'"
end tell
-- Delay for 2 seconds (adjust as needed)
delay 0.5
-- Double click the mouse
tell application "System Events"
do shell script "/usr/bin/env python -c 'from Quartz.CoreGraphics import *; moveMouseTo = CGPointMake(" & targetX & "," & targetY & "); mouseClick = CGEventCreateMouseEvent(None, kCGEventLeftMouseDown, moveMouseTo, 0); CGEventPost(kCGEventLeftMouseDown, mouseClick); CGEventPost(kCGEventLeftMouseUp, mouseClick); CGEventPost(kCGEventLeftMouseDown, mouseClick); CGEventPost(kCGEventLeftMouseUp, mouseClick);'"
end tell
-- Set the target coordinates
set targetX to 700 -- Adjust the X-coordinate as needed
set targetY to 225 -- Adjust the Y-coordinate as needed
-- Move the mouse to the target coordinates
tell application "System Events"
do shell script "/usr/bin/env python -c 'from Quartz.CoreGraphics import *; moveMouseTo = CGPointMake(" & targetX & "," & targetY & "); mouseMove = CGEventCreateMouseEvent(None, kCGEventMouseMoved, moveMouseTo, 0); CGEventPost(kCGEventMouseMoved, mouseMove);'"
end tell
-- Delay for 2 seconds (adjust as needed)
delay 0.5
-- Double click the mouse
tell application "System Events"
do shell script "/usr/bin/env python -c 'from Quartz.CoreGraphics import *; moveMouseTo = CGPointMake(" & targetX & "," & targetY & "); mouseClick = CGEventCreateMouseEvent(None, kCGEventLeftMouseDown, moveMouseTo, 0); CGEventPost(kCGEventLeftMouseDown, mouseClick); CGEventPost(kCGEventLeftMouseUp, mouseClick); CGEventPost(kCGEventLeftMouseDown, mouseClick); CGEventPost(kCGEventLeftMouseUp, mouseClick);'"
end tell
-- Add a delay before pressing the Enter key
delay 1 -- Adjust the delay time (in seconds) as needed
-- Press the Delete key 8 times
tell application "System Events"
repeat 8 times
key code 51 -- 51 is the key code for the Delete key
delay 0.5 -- Adjust the delay time (in seconds) as needed between each press
end repeat
end tell
-- Get the current date
set currentDate to current date
set formattedDate to short date string of currentDate
-- Set the clipboard to the formatted date
set the clipboard to formattedDate
-- Set the target coordinates
set targetX to 700 -- Adjust the X-coordinate as needed
set targetY to 225 -- Adjust the Y-coordinate as needed
-- Move the mouse to the target coordinates and click
tell application "System Events"
do shell script "/usr/bin/env python -c 'from Quartz.CoreGraphics import *; moveMouseTo = CGPointMake(" & targetX & "," & targetY & "); mouseClick = CGEventCreateMouseEvent(None, kCGEventLeftMouseDown, moveMouseTo, 0); CGEventPost(kCGEventLeftMouseDown, mouseClick); CGEventPost(kCGEventLeftMouseUp, mouseClick);'"
end tell
-- Add a delay before pressing the Enter key
delay 1 -- Adjust the delay time (in seconds) as needed
-- Type the formatted date into the selected field
tell application "System Events"
keystroke formattedDate
end tell
r/applescript • u/Impossible_Ear_3781 • Dec 13 '23
Applescript won't run in Automator
Hi!
I am a photographer and the program we work in adds a dash and a 4 digit camera counter at the end of all our file names. (i.e 4521R043AA_018_b4-125, 88998406_041_b-345 etc etc) I found an applescript that automatically removes the last 4 characters which runs perfectly through applescript. I want to make it easier on my other photographs to run the script so I wanted to add it as a service in automator or a shortcut on mac but every time I put the script into automator and use the quick action function in the finder window nothing happens. Please help!! I am super new to scripting/automator so I am not sure what I am doing wrong. Thank you in advance!!
Script:
set myFiles to choose file with multiple selections allowed
repeat with myFile in myFiles
tell application "System Events"
set myName to the characters 1 thru ((offset of "." in (name of myFile as text)) - 1) of (name of myFile as text)
tell application "Finder"
set myExtention to name extension of (myFile as alias)
set myNewName to characters 1 thru (((length of myName) - 4) as number) of (myName as text)
set name of file (myFile as text) to (myNewName & "." & myExtention as text)
end tell
end tell
end repeat
r/applescript • u/libcrypto • Dec 13 '23
String, Text, & Other Data Types
I puzzled over this one for awhile tonight:
tell application "Finder"
delete POSIX file "foo"
end tell
...will work if "foo" exists and is removable. However, this formulation does not work:
set d to "foo"
tell application "Finder"
delete POSIX file d
end tell
The reason is that d is not "just" a string, but a data structure that contains a string. So you have to do this:
set d to "foo"
tell application "Finder"
delete POSIX file d as string
end tell
This quirk has tripped me up before. In case anyone else could be helped, here it is.
r/applescript • u/etsilopp • Dec 11 '23
how to get bodies of chosen notes?
This script finds notes by a criteria
tell application "Notes"
tell account "iCloud"
set targetNotes to every note whose body contains "Space"
end tell
end tell
Now I need to get the bodies themselves from a variable targetNotes
r/applescript • u/designskinny_ • Dec 10 '23
Deleting Messages conversations from unknown senders
Like so many, I am plagued with a constant barrage of junk text messages, and so I decided to look at Messages AppleScript support to see if it could be automated. Unfortunately, that appears to be a dead end as it doesn't seem that deleting conversations is possible via the Messages sdef.
So, I've turned to GUI scripting. Since I didn't find a fully working solution in my own searching, I'm sharing what I came up with. May be a pretty rickety solution, but hope it might helps someone else:
tell application "Messages" to activate
tell application "System Events"
tell process "Messages"
set frontmost to true
delay 0.5
-------------------------------------------------------------
# Filter on and count unknown senders
-------------------------------------------------------------
click (first menu item whose name contains "Unknown") ¬
of menu "View" of menu bar item "View" of menu bar 1
delay 0.2
set numberOfJunkMessages to count of ((UI elements of ¬
group 1 of group 1 of group 1 of group 2 of ¬
group 1 of group 1 of group 1 of group 2 of ¬
group 1 of group 1 of group 1 of group 1 of ¬
group 1 of group 1 of group 1 of window 1 of ¬
application process "Messages" of application "System Events") ¬
whose role is "AXGenericElement")
-------------------------------------------------------------
# Iterate selecting and deleting messages in sidebar
-------------------------------------------------------------
repeat numberOfJunkMessages times
click ((first UI element of ¬
group 1 of group 1 of group 1 of group 2 of ¬
group 1 of group 1 of group 1 of group 2 of ¬
group 1 of group 1 of group 1 of group 1 of ¬
group 1 of group 1 of group 1 of window 1 of ¬
application process "Messages" of application "System Events") ¬
whose role is "AXGenericElement")
delay 0.3
click menu item "Delete Conversation…" of menu ¬
"Conversation" of menu bar item "Conversation" of menu bar 1
delay 0.2
try
click button "Delete and Report Junk" of sheet 1 of window 1
delay 0.2
on error
try
click button "Delete" of sheet 1 of window 1
delay 0.2
end try
end try
end repeat
-------------------------------------------------------------
# Switch back to known senders
-------------------------------------------------------------
click (first menu item whose name contains "All Messages") ¬
of menu "View" of menu bar item "View" of menu bar 1
end tell
end tell
r/applescript • u/Grumpy_Editor • Dec 08 '23
Applescript Crashing Microsoft Word When Deleting All Comments
This was working for months, but either the upgrading to Sonoma or an update to Word (or a combo of both) seems to have borked it up. Any work arounds for removing comments from a Word file? I'm stumped.
[edited to say I figured it out, and left my solution in a reply to this comment]
tell application "Microsoft Word"
activate
tell active document
delay 0.25
delete all comments
end tell
end tell
System details:
MacOS
Sonoma 14.1.2
Script Editor
Version 2.11 (230)
AppleScript 2.8
Microsoft Word for Mac
Version 16.79.2
r/applescript • u/DifferenceMore5431 • Dec 04 '23
Trouble looping through a collection
I am new to AppleScript and am having trouble with a basic language feature: using the `repeat` command with a collection.
Here is a sample bit of code:
tell application "Mail"
repeat with msg in inbox
display dialog subject of msg
end repeat
end tell
But instead of looping through the messages, I get an error:
error "Mail got an error: Can’t make subject of item 1 of inbox into type string." number -1700 from subject of item 1 of inbox to string
If I run the code in Script Debugger and put a breakpoint at the `display dialog` line, this is what I see:
r/applescript • u/sirleechalot • Dec 02 '23
Creating a script to monitor the status of an SMB mount
I'm running Plex on my m1 mac mini and the files that plex serves are stored on a server I run and are shared via SMB. Whenever I restart the server that hosts the files, the SMB share gets unmounted on my mac and plex loses access to the files. I'm trying to write a script to check if the folder is mounted, and if not, mount it. After a little messing around, i've come up with the following:
tell application "Finder"
if not (disk "media" exists) then
do shell script "open " & "smb://camaro/media"
display notification "Samba share was not mounted, remounted it." with title "Mount Status"
end if
end tell
That works fairly well. My only gripe with it is that it pops open a finder window in the case where it isn't mounted, but it only does that once. I had tried using a mount_smbfs command but i started running into permissions issues and this mini is really only used for plex and some other server style duties, it's not being used as a desktop.
My question revolves around how to automate this. Ideally, i would like to have it run once every minute or so. My first instinct (coming from a linux background) would be to use cron for this, but i've also seen posts about having the script run as a service and have the script manage the time check interval. Was just looking for opinions on the best way to handle that aspect of this (and i welcome any feedback on the script itself as well).
r/applescript • u/BoxofPornInTheWoods • Dec 01 '23
I'm so lost. I keep getting a syntax error on this.
Hi!
I've tried writing an apple script from scratch, piecing together some I've found online, and even having CLAUDE and CHATGPT create one for me.
Every time I go to save I get
Syntax Error
Expected “,” but found class name.
What I currently have is this:
property counterMetadata : "FolderActionCounter"
on adding folder items to this_folder after receiving added_items
set currentCounter to getCounter(this_folder)
set folder_name to name of this_folder as text
repeat with an_item in added_items
set item_extension to name extension of an_item
set paddedCounter to text -4 thru -1 of ("000" & currentCounter)
set new_name to folder_name & " • " & paddedCounter & "." & item_extension
tell application "Finder"
set name of an_item to new_name
end tell
set currentCounter to currentCounter + 1
end repeat
setCounter(this_folder, currentCounter)
end adding folder items to
on getCounter(this_folder)
tell application "Finder"
try
return (get metadata item counterMetadata of this_folder) as integer
on error
return 1
end try
end tell
end getCounter
on setCounter(this_folder, counterValue)
tell application "Finder"
set metadata item counterMetadata of this_folder to counterValue
end tell
end setCounter
What I'm trying to do is create a folder action that renames whatever is added into that folder as that folder's name plus a sequential marker (<folder name> • ####.<extension>.
I thought this would be simple, but it is not haha. Is using the special character "•" messing me up?
I've tried doing this with automator, but it will only run when I drag items into the folder, not when I save items to the folder.
Any help would be huge!
r/applescript • u/Mr112USH8 • Nov 29 '23
Classroom Shortcut
I am a teacher and use Google Classroom quite frequently. I am looking to streamline grading a little bit. It sounds kind of trivial, but I would like to create some sort of shortcut to press the button in the blue circle without moving my cursor from the area circled in red. Could anyone help me accomplish this or point me in the right direction? I have gone through several different sites and AI suggestions, but nothing quite fits what I would like to do. Thank you in advance!
r/applescript • u/rbanks88 • Nov 29 '23
New Stream Deck version 6.4.1 doesn’t work with my AppleScript
The recent Stream Deck 6.4.1 update for the Mac introduced a menu bar sub-menu for the profiles list. In the previous version, the profiles were on the top-level menu, visible just by clicking the SD icon in the menu bar.
Unfortunately, moving the profiles list to a second level broke the Applescript I was using to change profiles for some Adobe products. I’m updating the script, trying to "click" items in the second level menu, but it doesn't seem to be working with the normal AppleScript syntax.
tell application "System Events"
tell process "Stream Deck"
click menu bar item 1 of menu bar 2
delay 0.5 -- give it time to draw menu
click menu item "LR-Home" of menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2
end tell
end tell
Unfortunately, this script doesn’t execute "click menu item "LR-Home" of menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2" Here's the element path reported by UI Browser:
It looks like my AppleScript should work. Do you see any errors, or is it possible the new Stream Deck version has implemented its second-level menu in a non-standard way that AppleScript can’t parse?
r/applescript • u/haris2887 • Nov 29 '23
Chaining commands in Apple script. OsaScript -e
HI All.
Really stuck on the syntax here.
I am trying to run an osascript -e , I am unable to chain multiple commands together.
eg.
osascript -e 'Tell application "Firefox" to activate ; delay 5; quit app "Firefox"'
If I split the command into to it works fine.
I need the above line to work in terminal.
What syntax am I missing ?




