Skip to content

Instantly share code, notes, and snippets.

@crbyxwpzfl
Last active November 12, 2022 17:16
Show Gist options
  • Save crbyxwpzfl/f0775a27cadbb3b66dae03de2f767aa0 to your computer and use it in GitHub Desktop.
Save crbyxwpzfl/f0775a27cadbb3b66dae03de2f767aa0 to your computer and use it in GitHub Desktop.
apple script find a imessage to automate tapback for any message
on run argv
tell application "System Events" to tell process "Messages"
set frontmost to true
tell application "System Events" to keystroke "f" using command down
tell application "System Events" to keystroke item 1 of argv
tell application "System Events" to keystroke return
delay 1
perform action "AXPress" of static text 2 of group 1 of group 3 of group 1 of group 1 of group 1 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
delay 1
set smalerlist to (entire contents of group 1 of group 1 of group 1 of group 1 of group 3 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of window 1 as list)
repeat with n from 1 to count of smalerlist
if (value of item n of smalerlist contains item 1 of argv) then
perform action "AXPress" of item n of smalerlist
exit repeat
end if
end repeat
delay 1
if item 2 of argv = "del" then
tell application "System Events" to key code 51
tell application "System Events" to keystroke return
end if
if item 2 of argv = "tap" then
tell application "System Events" to keystroke "t" using command down
tell application "System Events" to keystroke item 3 of argv
end if
end tell
end run
tell application "System Events" to tell process "Messages"
set frontmost to true
set txt to "Wow"
tell application "System Events" to keystroke "f" using command down
tell application "System Events" to keystroke txt
tell application "System Events" to keystroke return
delay 1
set listItems to (entire contents of window 1 as list)
repeat with i from 1 to count of listItems
if (description of item i of listItems is txt) then
log ("actions of first search reslut")
log (get actions of item i of listItems)
perform action "AXPress" of item i of listItems
exit repeat
end if
end repeat
delay 1
repeat with n from 1 to count of listItems
if (value of item n of listItems contains txt) and (description of item n of listItems is "text entry area") then
log ("actions of message bubble")
log (get actions of item n of listItems)
log (get description of item n of listItems)
log (get value of item n of listItems)
perform action "AXPress" of item n of listItems
exit repeat
end if
end repeat
delay 2
tell application "System Events" to keystroke "t" using command down
tell application "System Events" to keystroke "1"
end tell
@crbyxwpzfl
Copy link
Author

crbyxwpzfl commented Nov 3, 2022

current state - prettier but a lot slower. not good as well

original - hi my apple script is bad please help make this fuck prettier, this was so hard for me to put to gether.
finding all the nested ui groups corectly was so tedious.

info links i used to pice this together search lists 1 / search lists 2 / find uielemnt 1 / find uielemnt 2 / find uielemnt 3

further ranting.… apples accessibility inspector was not telling me the correct hirachy but perhaps that was user error.
anyway finally found the right ui groups by manually returning Ui elemnts one group deeper at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment