Created
January 3, 2019 15:02
-
-
Save gouf/e5538294c6cc05ebea16a716c3f3cb6d to your computer and use it in GitHub Desktop.
AppleScript: Slack のステータス メッセージを変更する。アイコンは muscle 固定でそれに変更
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
property statusMessageAs : "" | |
on run argv # TIPS: {"arg1", "arg2"...} と複数設定できる | |
if (count of argv) > 0 then | |
set statusMessageAs to argv | |
else | |
set statusMessageAs to "AppleScriptIsFun" | |
end if | |
# NOTE: すでにアプリケーションが起動している必要がある | |
tell application "Slack" | |
activate | |
delay 0.2 | |
# キーストロークをシステムイベントとして送信 | |
# NOTE: 適宜 delay を入れないと操作が速すぎて 受け付けてもらえない | |
tell application "System Events" | |
# すでに何か表示されてたときのために ESC キーで非表示にする | |
key code 53 # esc | |
delay 0.5 | |
# ステータス変更のショートカットキー | |
keystroke "y" using {command down, shift down} | |
delay 1.8 | |
# すでに入力されている内容を削除 | |
keystroke "a" using command down | |
delay 0.1 | |
key code 51 # DEL | |
# 内容の打ち込み | |
# FIXME: 日本語部分, スペース含む英数字が入力できない | |
keystroke statusMessageAs | |
delay 1.0 | |
# ステータスアイコンの変更 | |
# キーボード操作で変更メニューまでたどり着く | |
# Tab(48) @ 1, return, muscle | |
key code 48 | |
delay 1.0 | |
key code 49 # Space | |
delay 0.5 | |
keystroke "muscle" | |
delay 0.1 | |
key code 36 # Enter | |
delay 0.1 | |
# 変更内容の保存 | |
# キーボード操作で変更メニューまでたどり着く | |
# Tab @ 4, return | |
repeat with i from 1 to 4 | |
key code 48 # Tab | |
delay 0.1 | |
end repeat | |
keystroke return | |
end tell | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment