自室用にMajestouchを購入したのを機にSeilとKarabinerを導入したけど、
メイン機がMacBookProなので外で作業するときにいちいち上記のソフトを起動終了するのが面倒になったので、さくっとスクリプトを組んだ。
キーボードの製品IDを予めシステムプロファイラから確認して登録しておくだけで起動と終了をスイッチしてくれるやつです。
kbchecker.scpt
set keyboard_id to "0x4545"
set KB to missing value
try
set KB to paragraphs of (do shell script "system_profiler SPUSBDataType -detaillevel mini | grep " & keyboard_id)
end try
set pl to missing value
tell application "System Events"
-- プロセス取得
set pl to name of every process
end tell
if KB is equal to missing value then
-- キーボードがない時はkarabinerとseilを終了
try
do shell script "pkill Seil"
do shell script "pkill Karabiner"
on error
display alert "起動していない状態なので終了します。"
return
end try
display alert "Quit OK"
return
else
tell application "Seil" to run
tell application "Karabiner" to run
display alert "Launch OK"
return
end if
後はアプリケーションとして保存してDockとログイン時リストに登録しておくだけで、内蔵と外付けとでうまいこと切り替えることが出来ます。
追記:
karabiner終了時にそもそも起動していなかった時の例外処理を入れていなかったので入れました。