Last active
October 20, 2022 15:51
-
-
Save EricLondon/d2c78952471cab05b59a9a1aa4d0b9e6 to your computer and use it in GitHub Desktop.
imessage.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$#" -eq 1 ]; then stdinmsg=$(cat); fi | |
exec <"$0" || exit; read v; read v; read v; exec /usr/bin/osascript - "$@" "$stdinmsg"; exit | |
on appIsRunning(appName) | |
application appname is running | |
end appIsRunning | |
-- taken from: | |
-- http://stackoverflow.com/questions/11812184/how-to-send-an-imessage-text-with-applescript-only-in-provided-service | |
-- thanks to users @Senseful and @DigiLord | |
on run {targetBuddyPhone, targetMessage} | |
tell application "Messages" | |
-- if Messages.app was not running, launch it | |
set wasRunning to true | |
if it is not running then | |
set wasRunning to false | |
launch | |
close window 1 | |
my waitUntilRunning("Messages", 1) | |
close window 1 | |
end if | |
-- send the message | |
set targetService to 1st service whose service type = iMessage | |
set targetBuddy to buddy targetBuddyPhone of targetService | |
send targetMessage to targetBuddy | |
-- if the app was not running, close the window | |
if not wasRunning | |
close window 1 | |
end if | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment