標籤:
本人用AppleScript成功實現了開啟銳捷app,並且在使用者驗證框輸入我的使用者密碼,然後強制退出銳捷。(至於為什麼這麼做呢?用校園網的痛苦,一言難盡啊!)
學習以下內容,首先你要自行百度資料來學習一點內容,學會使用工具 + 生產力裡面的 指令碼編輯器 和 Automator。工具 + 生產力,確實很實用啊!
--指令碼完成按鍵組合按下 by Ficowtell application "System Events" key code 53 using {command down, option down}end tell-- --這個符號是注釋符號,(**)這個也是注釋符號,類似於C語言裡面的//和/**/-- key code 53的意思按下Esc鍵,53的含義見下面的列表-- using {} 花括弧部分按下的按鍵和前面的按鍵事件一起作用-- command down, option down的含義是按下command和option-- 所以這個指令碼的作用就是啟動強制退出視窗(command+option+Esc)(*apple key code list:0 0x00 ANSI_A1 0x01 ANSI_S2 0x02 ANSI_D3 0x03 ANSI_F4 0x04 ANSI_H5 0x05 ANSI_G6 0x06 ANSI_Z7 0x07 ANSI_X8 0x08 ANSI_C9 0x09 ANSI_V10 0x0A ISO_Section11 0x0B ANSI_B12 0x0C ANSI_Q13 0x0D ANSI_W14 0x0E ANSI_E15 0x0F ANSI_R16 0x10 ANSI_Y17 0x11 ANSI_T18 0x12 ANSI_119 0x13 ANSI_220 0x14 ANSI_321 0x15 ANSI_422 0x16 ANSI_623 0x17 ANSI_524 0x18 ANSI_Equal25 0x19 ANSI_926 0x1A ANSI_727 0x1B ANSI_Minus28 0x1C ANSI_829 0x1D ANSI_030 0x1E ANSI_RightBracket31 0x1F ANSI_O32 0x20 ANSI_U33 0x21 ANSI_LeftBracket34 0x22 ANSI_I35 0x23 ANSI_P36 0x24 Return37 0x25 ANSI_L38 0x26 ANSI_J39 0x27 ANSI_Quote40 0x28 ANSI_K41 0x29 ANSI_Semicolon42 0x2A ANSI_Backslash43 0x2B ANSI_Comma44 0x2C ANSI_Slash45 0x2D ANSI_N46 0x2E ANSI_M47 0x2F ANSI_Period48 0x30 Tab49 0x31 Space50 0x32 ANSI_Grave51 0x33 Delete53 0x35 Escape55 0x37 Command56 0x38 Shift57 0x39 CapsLock58 0x3A Option59 0x3B Control60 0x3C RightShift61 0x3D RightOption62 0x3E RightControl63 0x3F Function64 0x40 F1765 0x41 ANSI_KeypadDecimal67 0x43 ANSI_KeypadMultiply69 0x45 ANSI_KeypadPlus71 0x47 ANSI_KeypadClear72 0x48 VolumeUp73 0x49 VolumeDown74 0x4A Mute75 0x4B ANSI_KeypadDivide76 0x4C ANSI_KeypadEnter78 0x4E ANSI_KeypadMinus79 0x4F F1880 0x50 F1981 0x51 ANSI_KeypadEquals82 0x52 ANSI_Keypad083 0x53 ANSI_Keypad184 0x54 ANSI_Keypad285 0x55 ANSI_Keypad386 0x56 ANSI_Keypad487 0x57 ANSI_Keypad588 0x58 ANSI_Keypad689 0x59 ANSI_Keypad790 0x5A F2091 0x5B ANSI_Keypad892 0x5C ANSI_Keypad993 0x5D JIS_Yen94 0x5E JIS_Underscore95 0x5F JIS_KeypadComma96 0x60 F597 0x61 F698 0x62 F799 0x63 F3100 0x64 F8101 0x65 F9102 0x66 JIS_Eisu103 0x67 F11104 0x68 JIS_Kana105 0x69 F13106 0x6A F16107 0x6B F14109 0x6D F10111 0x6F F12113 0x71 F15114 0x72 Help115 0x73 Home116 0x74 PageUp117 0x75 ForwardDelete118 0x76 F4119 0x77 End120 0x78 F2121 0x79 PageDown122 0x7A F1123 0x7B LeftArrow124 0x7C RightArrow125 0x7D DownArrow126 0x7E UpArrow*)
這裡附上我自己製作的Automator服務:
首先在Automator,添加服務。
開啟Automator,建立服務,
然後,添加啟動銳捷的功能(雙擊開啟應用程式,右邊就回出現可以配置的功能塊):
啟動銳捷後需要輸入自己的使用者密碼,所以緊接著就插入完成按鍵按下的指令碼,完成密碼的自動輸入:
your script goes here,好的,就在這下面開始寫輸入密碼的指令碼吧:
on run {input, parameters} (* Your script goes here *) delay 1 --延時1S後執行後面的內容 tell application "System Events" key code 1 --這裡做示範,只輸入了小寫s,code編碼請參照key code list key code 76 --輸入了斷行符號,以確認密碼輸入 end tell delay 10 --延時10S,等待銳捷啟動並自動登入完畢 return inputend run
接下來,添加再一個指令碼,輸入終結銳捷的指令碼代碼:
on run {input, parameters} (* Your script goes here *) beep --讓Mac發出聲音 tell application "System Events" key code 53 using {command down, option down} --按下開啟強制退出框的按鍵組合 delay 1 key code 76 --確定選擇 delay 1 key code 76 --確定退出銳捷 end tell --tell和end tell需要配對使用 return inputend run
可參考資料:
http://www.guokr.com/blog/792617/
http://apple.stackexchange.com/questions/36943/how-do-i-automate-a-key-press-in-applescript
Mac AppleScipt 自動完成按鍵