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
53 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?
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?
I get the error code: System Events got an error: Can't get application of "Application Name" during this line
repeat with currentWindow in every window of application foregroundApp
of this code
on run
tell application "System Events"
set foregroundApps to displayed name of (every process whose background only is false) as list
repeat with foregroundApp in foregroundApps
set appName to foregroundApp as text
if exists (window 1 of process appName) then
repeat with currentWindow in every window of application foregroundApp
end repeat
end if
end repeat
end tell
end run
I'm guessing I'm missing something like
set x to foregroundApp as y
repeat with currentWindow in every window of application x
How do I get the windows of the application foreground app?
Hi,
So I've been trying to set up this applescript which removes Emojis from filenames in my Download folder. Right now it's set up to work with a droplet, but for some reason I get an error message when running the script. This is my error message:
Can’t get name of alias "Macintosh HD:Users::Downloads:Armandocolor IDREAM - Alone RMX BURNAxBOY ❤️❤️❤️❤️❤️❤️.mp3".
This is my scriptcode:
-- Prompt user to choose files
set selectedFiles to choose file with prompt "Select files to remove emojis from:" with multiple selections allowed
processFiles(selectedFiles)
end run
on open theFiles
-- Called when files are dropped onto the droplet
processFiles(theFiles)
end open
on processFiles(fileList)
repeat with aFile in fileList
set fileName to name of aFile
set newName to removeEmojisFromText(fileName)
-- Check if the filename changed
if newName is not equal to fileName then
set name of aFile to newName
end if
end repeat
end processFiles
on removeEmojisFromText(inputText)
set outputText to ""
repeat with i from 1 to count characters of inputText
set thisChar to character i of inputText
if (thisChar is not in {"", return, tab}) then
try
set outputText to outputText & thisChar
end try
end if
end repeat
return outputText
end removeEmojisFromText
Can someone help me out with this code? I'm very much a noob still at applescripting...
I'm looking to develop an application that can enable the Supervision Mode on an iOS device that is connected over a USB cable.
For this, I'm looking to use Apple Configurator's Configuration Utility which has Handlers such as "CNFGPrepareSpecifiedDevices". I'm planning to invoke the " (script library)" and call CNFGPrepareSpecifiedDevices along with the required parameters from my application.
This will have a dependency on the Apple Configurator installed on the Mac.
Is calling the Configuration Utility scripts and handlers within my application legally allowed by Apple?
Or is there any alternative approach someone can suggest?
I'm trying to automate making accurate alarms to help me estimate when I need to leave to be on time for meetings.
To do this accurately, I want to access Apple Maps (or Google Maps services, or ...) to get an estimate of driving times given current driving conditions. So I'd like to query the maps service reasonably close to departure time. (If I get an estimate on Sunday evening at for an appoint on Monday at rush hour leaving from a different location, it's obviously going to be inaccurate.)
Ideally, I'd like to directly access my Apple Calendar to get the appointments and their locations. But if that's too complicated, I'll just create a formatted text file or sqlite file or whatever with the information.
I've considered doing this with Shortcuts, Automator, AppleScript, JXA, Hammerspoon, Python, etc. It seems that each technology has part of what I need, but not all. But I don't have deep knowledge of any of them. Perhaps someone can advise me on the most appropriate technology.
Here are my impressions:
Shortcuts: Has built in access to driving time estimates and Calendar events, but awkward and possibly too limited in terms of program logic.
Automator: Is more capable than Shortcuts in some ways, less in others.
AppleScript: I don't know.
JXA: I prefer Javascript to AppleScript, but it seems hard to find good documentation.
Python: I'm quite proficient in Python, but I don't know if I can access things like Calendar events. If not, I'm willing to keep a separate file manually. (I could perhaps create the Calendar events from this, except that some appointments are set up by my work.)
Hammerspoon: I don't have any experience with it and don't know it's capabilities.
Any advice appreciated.