Skip to content

Instantly share code, notes, and snippets.

@gouf
Created January 3, 2019 12:39
Show Gist options
  • Save gouf/16dd73a334f5123d4cb5151900ce76f4 to your computer and use it in GitHub Desktop.
Save gouf/16dd73a334f5123d4cb5151900ce76f4 to your computer and use it in GitHub Desktop.
AppleScript: 与えられた引数をもとに Slack アプリのチャンネル表示を切り替える
property channelName : ""
on run argv # TIPS: {"arg1", "arg2"...} と複数設定できる
if (count of argv) > 0 then
set channelName to argv
else
set channelName to "my_home_channel"
end if
# NOTE: すでにアプリケーションが起動している必要がある
tell application "Slack"
activate
delay 0.2
# キーストロークをシステムイベントとして送信
# NOTE: 適宜 delay を入れないと操作が速すぎて 受け付けてもらえない
tell application "System Events"
keystroke "k" using command down
delay 1.0
keystroke channelName
delay 0.5
keystroke return
delay 0.5
key code 53 # 該当チャンネルがなかった場合作る画面に切り替わるので esc で抜ける
end tell
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment