This code sends a text message from the command line
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = SMS
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
And this code sends an iMessage from the command line
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
I’m looking for a solution to combine this code into a single snippet that will try to send an iMessage if the recipient has iMessages, but if they do not, then the code will send a SMS message.
AppleScript
RSS for tagAppleScript allows users to directly control scriptable Macintosh applications as well as parts of macOS itself.
Posts under AppleScript tag
55 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I know that zoom.us is not technically scriptable with Applescript but I have gotten so tired of repeatedly doing the same things when I set up a Zoom session that I started trying to automate the process using System Events and tell process. I was surprised by how much I could automate but then ran into a couple of brick walls. If anyone else is interested in this I'd like to brainstorm on the forum to see how much is possible.
Here's some scripting steps I have been playing with. Part of what I decided to do in order to simplify the data entry involved in scheduling a new meeting and sending an email to the client was to run everything from Filemaker. The variables shows as $theMonth, $theDay, etc are being set in FileMaker before the Perform Applescript step so this is not a viable Applescript. You could use three separate Applescript dialog boxes to get the name date and time. The key code 48 is a tab to move between fields on the zoom interface. Key code 76 is the enter key which will OK the automatic entries in the Calendar so that I can quit Calendar and get back to zoom. There seems to be no way to stop zoom from automatically posting a new session in the Calendar.
tell application "zoom.us" to activate
tell application "System Events"
tell process "zoom.us"
repeat until window "Schedule Meeting" exists
click menu item "Schedule Meeting..." of menu "Zoom.us" of menu bar 1
delay 0.2
end repeat
set topicField to text field 1 of "Schedule Meeting"
keystroke "Whatever You Want It To Be""
key code 48
keystroke $theMonth as text
key code 48
keystroke $theDay as text
key code 48
keystroke $theYear as text
key code 48
keystroke $theHour as text
key code 48
keystroke $theMinute as text
key code 48
keystroke $theMonth as text
key code 48
keystroke $theDay as text
key code 48
keystroke $theYear as text
key code 48
keystroke ($theHour + 1) as text
key code 48
keystroke $theMinute as text
Delay 2
key code 36
key code 76
key code 76
end tell
end tell
tell application "Calendar" to quit
tell application "zoom.us" to activate
tell application "System Events"
tell process "zoom.us"
repeat until window "Schedule Meeting" exists
click menu item "Schedule Meeting..." of menu "Zoom.us" of menu bar 1
delay 0.2
end repeat
select button ??????
end tell
end tell
The zoom.us interface for Meetings has what appear to be buttons for each scheduled meeting. I am trying to figure out how to select the right button so that I can then copy the invitation to put in an email. Tabbing does not let me select the button. If anyone has any ideas, I'd love to hear them, and if my further experiments produce any results, I'll post them.
Thanks
I would like to automate opening two finder windows in split-screen View (the full screen split view you get by hovering over the green full-screen button and selecting Tile Window, not the windows style maximize) If possible preferably via AppleScript but would be okay with Automator or shortcuts. Any help would be greatly appreciated. Running an M1 Air on Monteray. my current workaround is this AppleScript, however, I would like to be using split-screen so it's in its on mission control workspace. PS New to mac and Applescript.
tell application "System Events" to set the autohide of the dock preferences to true
tell application "Finder"
close windows
open ("/Users/arthur/" as POSIX file)
set screenBounds to bounds of window of desktop
set screenWidth to item 3 of screenBounds
set screenHeight to item 4 of screenBounds
set the position of the front Finder window to {0, 0}
set the bounds of the front Finder window to {0, 0, screenWidth * 0.5, screenHeight * 1}
make Finder window
set the position of the front Finder window to {screenWidth * 0.5, 0}
set the bounds of the front Finder window to {screenWidth * 0.5, 0, screenWidth, screenHeight * 1}
set the target of Finder window 1 to ("/Users/arthur/Downloads" as POSIX file)
activate
end tell
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?
Hi Everyone,
I'm new to mac's and AppleScript so I apologise in advance for the level of questioning/quality of code.
I've been trying to create an applescript to go through every menuitem and list out the keyboard shortcuts. I've created a script to add keyboard shortcuts, but have only done so as global shortcuts. Some of them don't work in different apps so I'm trying to create a verbose list that has every menuitem for every application so I can populate my script, then eventually have application specific shortcuts for every menuitem that has a shortcut currently.
Below I'm trying to generate that list of current shortcuts but I'm stuck on the syntax of getting the properties of attributes of items and displaying them.
The below is where I have got to:
set allMenus to {}
set everything to {}
set onlyEnabled to {}
tell application "System Events" to tell process appName
set allMenus to name of every menu of menu bar 1
end tell
global testCounter
global currentCounter
set testCounter to 14
set currentCounter to 0
repeat with menuName in allMenus
set the end of everything to strings of getAppMenuItems(appName, menuName, onlyEnabled)
if currentCounter > testCounter then
log "EXIT REPEAT!!!!!!!!!!!!!!!"
exit repeat
end if
end repeat
on getAppMenuItems(appProcess, appMenus, enabledItems)
tell application "System Events" to tell process appProcess
# Get all menu items
set theItems to every menu item of menu appMenus of menu bar 1
log "BREAKAKKKKKKBREAKKKKKK"
set appMenuName to name of menu appMenus of menu bar 1
--log appname
repeat with theMenuItem in theItems
set currentCounter to currentCounter + 1
if currentCounter > testCounter then
exit repeat
end if
set itemAttrib to get every attribute of theMenuItem
repeat with aAttrib in itemAttrib
if the name of the aAttrib is "AXMenuItemCmdChar" then
set props to get properties of attribute "AXMenuItemCmdChar" of every menu item of menu appMenus of menu bar 1
repeat with aProps in props
if the value of aProps as text is not "missing value" then
log (appMenuName & "->" & name of theMenuItem as text & "->" & value of aProps as text)
end if
end repeat
log (appMenuName & "->" & name of theMenuItem as text & "BREAKAKKKKKKBREAKKKKKK")
end if
end repeat
end repeat
return name of every menu item of menu appMenus of menu bar 1
end tell
end getAppMenuItems
(*
tell application "System Events"
get name of menu item 2 of menu 3 of menu bar 1 of process "Finder"
--> "New Folder"
get every attribute of menu item 2 of menu 3 of menu bar 1 of process "Finder"
--> {attribute "AXRole" of menu item "New Finder Window" of menu "File" of menu bar item "File" of menu bar 1 of application process "Finder", [...]
get properties of attribute "AXMenuItemCmdChar" of [...]
--> {value:"N", class:attribute, settable:false, name:"AXMenuItemCmdChar"}
get properties of attribute "AXMenuItemCmdModifiers" of [...]
--> {value:1, class:attribute, settable:false, name:"AXMenuItemCmdModifiers"}
*)
Currently this outputs:
Apple->About This Mac->Q
Apple->About This Mac->Q
Apple->About This MacBREAKAKKKKKKBREAKKKKKK
Apple->System Information…->Q
Apple->System Information…->Q
Apple->System Information…->Q
From the output I have surmised that when I'm logging the output (log (appMenuName & "->" & name of theMenuItem as text & "->" & value of aProps as text) The properties aren't actually the properties of theMenuItem attribute, but that it has found 3 AXMenuItemCmdChar in the full Apple menu, and is just putting those 3 against each theMenuItem.
I've tried a few ways around this, mainly changing
set props to get properties of attribute AXMenuItemCmdChar of every menu item of menu appMenus of menu bar 1
to
set props to get properties of itemAttrib
or
set props to get properties of attribute "AXMenuItemCmdChar" of itemAttrib but can't seem to find the right way of getting it to work. Furthermore, how I would correctly reference the parent within my log() statement (I can see the syntax for referencing the child (e.g. x of y of z) but how do you go the other way?
Thanks in advance
Hi!
I am trying to set up some tests on AppleTV and i figured the way to do them is by using airplay video. The issue here is i want the tests to be automatically executed and i don't seem to see any way to automatize airplay except for using applescript with quicktime player. I tried to write a script that could do that but i get the "wrong index" error. My code below:
to replaceFrontQTPlayerWithFile(aFile)
tell application "QuickTime Player"
activate
try
set frontDoc to front document
close front document
on error err number errNum
if errNum is -1719 then
-- There is no open document
else if errNum is -10000 then
-- Front doc exists, but does not really...
else
log err
end if
end try
open aFile
tell application "System Events" to tell process "QuickTime Player"
tell window 1
click button 4
delay 1
pick menu item "WRO-CT-IE-ATV-2" of menu 0 of button 4
end tell
end tell
play front document
-- Hide QTP
#tell application "System Events"
# keystroke "h" using command down
#end tell
end tell
end replaceFrontQTPlayerWithFile
on run
set unixFile to "/Users/aet/signals/roomba_sdr_vfr_no_audio.mov"
set macFile to POSIX file unixFile
set fileRef to (macFile as alias)
my replaceFrontQTPlayerWithFile(fileRef)
end run
Here i have two questions:
Is there any other way to do that (maybe some airplay API/command line tool that could help me)?
If not is there a way to make my code work?
I am using macOS 12 device with tvOS 16 AppleTV
Recently we tested how to move app using Applescript as below picture and find some interesting phenomenon. The following coordinates are meant for the second screen, but only FaceTime cannot be moved to the second screen. It can only be moved within its own screen, while other apps can be smoothly moved to the second screen.
Because the syntax is exactly the same, could you help to guide us what is wrong with the script?
Sincerely, Thanks, Bruce
How would I select multiple rows programmatically (ie not using Keyboard or mouse simulation) in the "Open" dialog window in "Preview".
Manual Steps I'd take to do this in OSX Ventura 13.4.1
Open the "Preview" application.
From Preview's "File" menu, select "Open"
Wait for the dialog box whose title is "Open" to appear
Manually Select Row 1,3,5, and 7.
Fingers crossed that this is possible.
Thanks in advance!
Hello everyone,
Up to Monterey, a script we use to make it easier for users to change the password on their local account on the computer has worked very well. But after Monterey, it no longer works.
I've searched the web like crazy without finding any solution for Ventura. So I'm giving this form a shot in the hope that someone has a solution or something to help me along the way.
The main problem is to go from Users and Groups in System setting to the account detail where you can click the button for changing password. Anyone have any idea?
Code looks as follows:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
set userName to short user name of (system info)
-- Create a dialog with 3 buttons
display dialog "Mac Utility - user: " & userName buttons {"Change Password", "Forget Wi-Fi", "Cancel"} default button 1 with title "User Utilities" with icon caution
-- Open Users and Groups
if result = {button returned:"Change Password"} then
tell application "Finder" to open file "Accounts.prefpane" of (path to system preferences)
-- Show account details window
-- This is where I'm stuck
-- The rest of the script bellow
else if....
The earlier code looked as bellow that doesn't work with Ventura.
tell application "System Events"
tell application process "System Preferences"
delay 1
click button -1 of tab group 1 of window 1
end tell
end tell
Tanks in advance.
How to create a UTF-8 encoded text file using do shell script?
As I understand it, the command should start with do shell script. And what to write next?
How to do these actions using AppleScript:
launching the TextEdit program
setting TextEdit to be plain text (not formatted), UTF-8
creating an empty file
writing clipboard contents to a file
saving the file to the desktop
closing the file
Where can I see the entire list of commands for the "TextEdit" program? For example, there is a code:
tell application "TextEdit"
activate
make new document with properties {text:"XDXDXD"}
end tell
There are two commands in this code:
activate
make new document with properties {text:"XDXDXD"}
Where can I see all the available commands for the "TextEdit" program?
This code does not make sense, I would just like to get information based on it.
set MyData to "MyData1|MyData2"
on MyScript(MyData)
set MyVar1 to "MyData1"
set MyVar2 to "MyData2"
return MyVar1 & "|" & MyVar2
end MyScript
The text is passed in the code: "MyData1|MyData2". I need to divide it into two parts by the "|" symbol. And write each part into two variables: myVar1 and myVar2.
How to do it?
P.S. The problem is that only one parameter can be passed to on...end. I need to pass two. I'll pass one, then split it into two.
See the screenshots. First, the item "Commands Reference" is on the first level. I click on the arrow, the item "Commands Reference" goes to the second level. I click on the arrow again, the item "Commands Reference" remains in the second level.
Here is the help for the "open for access" command. In the Syntax - Parameters section, the first parameter is not specified, but immediately write something in parentheses. In the "write" command, it is done differently.
https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW31
All works well, except that 'Fwd:' in the subject line, which I'd like to remove when forwarding
tell application "Mail"
set theMessage to item 1 of (get selection)
set forwardedMessage to forward theMessage without opening window
tell forwardedMessage
make new to recipient at end of to recipients with properties {address:"a@b.com"}
set message signature of forwardedMessage to signature "Blank" of application "Mail"
set stringLength to (count subject of forwardedMessage)
set subject of forwardedMessage to (characters 0 thru stringLength) as string
send
end tell
end tell
REFERENCE old thread
Find path of the wallpaper image - Apple Community
previous to SONOMA you had a few options to locate the currently displayed desktop wallpaper. you can change the DOCK preference to enable the option to display the wallpaper path on the desktop
[defaults write com.apple.dock desktop-picture-show-debug-text -bool TRUE;killall Dock]
but this does not seem to be working anymore.
you were also able to run a AppleScript to locate and display the wallpaper file. this was done by querying the desktoppicture.db. but it does not appear that SONOMA utilizes this file anymore.
-- Usage: osascript find_wall_pic n
-- n = 1 or 2 (monitor ID)
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on run argv
if (count of argv) < 1 then
set screenId to 1
else
set screenId to item 1 of argv as integer
end if
if screenId ≤ 1 then
set screenId to 1 -- 1st monior index
else
set screenId to 18 -- 2nd monitor index
end if
set posixaliaspath to (do shell script "/usr/bin/sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"select d1.value || '/' || d2.value from preferences pf1 join data d1 on pf1.data_id=d1.rowid join preferences pf2 on pf1.picture_id=pf2.picture_id join data d2 on pf2.data_id=d2.rowid where pf1.key=10 and pf2.key=16 and pf1.picture_id=" & screenId & "\"") as string
set homepath to (do shell script "echo $HOME")
-- replace "~" in the path to actual $HOME dir
set posixaliaspath to replace_chars(posixaliaspath, "~", homepath)
set aliaspath to (POSIX file posixaliaspath) as string
set posixpath to POSIX path of aliaspath
set imgfile to POSIX file posixpath
-- tell application "Finder" to reveal imgfile
tell application "Finder"
activate
reveal imgfile
end tell
end run
I am looking for a solution similar to the AppleScript above, that can be run on demand to locate the file active on the desktop at that time. any ideas??
I'm trying to modify this code to work iteratively:
on run {input, parameters}
tell application id "com.apple.systemevents" to set the value of
attribute "AXMinimized" of every window of every process
to false
end run
Something along the lines of :
on run {input, parameters}
foreach windows of every process
tell application id "com.apple.systemevents" to set the value of
attribute "AXMinimized"
to false
end run
Is this possible?
I'm made a script that iterates through all windows and restores minimized windows. However, the script is quite slow. I'm wondering how to speed it up. I believe part of why the code is so slow is that it's looking at every process instead of every foreground process. Is it possible to do something like "repeat with p in every foreground process" or speed up this script through other means?
on run {input, parameters}
set windowNames to {}
tell application "System Events"
repeat with p in every process
repeat with w in every window of p
if value of attribute "AXMinimized" of w is true then
set value of attribute "AXMinimized" of w to false
end if
end repeat
end repeat
end tell
end run
I'm writing AppleScript to make a new folder action and attach it to a specified folder. In case there's already a folder action attached to the folder before make new folder action is executed, I want to delete that folder action already exists.
tell application "System Events"
repeat with i from 1 to count of folder actions
if (path of folder action i) as string is equal to "/Users/foo/MyFolder" then
delete folder action i
exit repeat
end if
end repeat
make new folder action at end of folder actions with properties {name:"MyFolderAction", path:"/Users/foo/MyFolder"}
end tell
However, it is still often that when make new folder action is executed, an error occured saying that "There is already a folder action with this path: /Users/foo/MyFolder".
Maybe it's because that when make new folder action is executed, the delete folder action has not completed yet. Adding a delay 1 before make new folder action makes the error occured less fruequently, but not disappeared.
Is there any method to confirm that the folder action is really deleted before make new folder action is executed?