如果你已經厭煩用鼠標操作來打開safari中的“開發->simulator->Url”來打開調試工具的話,這篇文章能幫助到你
本文中的腳本可以在github中查看
https://github.com/realjade/open-safari-simulator-applescript
配置Automator服務
1)在Launchpad中找到Automator,應該在《其他》里面,然后打開
2)在選取文稿類型的彈框中選擇“服務”,然后點擊選取,如下圖:
3)在“服務”收到的選擇框中選擇“沒有輸入”
4)在“實用工具 -> 《雙擊》運行AppleScript ”,會出現右邊的“運行AppleScript”腳本編寫框
5)把下面的腳本全部替換到框中即可
本文中的腳本可以在github中查看
https://github.com/realjade/open-safari-simulator-applescript
set urls to {}
tell application "System Events"
tell process "Safari"
set developMenu to menu 1 of menu item "Simulator" of menu 8 of menu bar 1
set allUIElements to entire contents of developMenu
repeat with anElement in allUIElements
try
set tmpName to name of anElement
log "sims: " & tmpName
set boolName to (offset of "." in tmpName) is not 0
if boolName is true then
set urls to urls & tmpName
end if
end try
end repeat
log urls
end tell
end tell
set urlLen to count of urls
if urlLen is 0 then
display dialog "沒有在模擬器中找到能debug的url"
else if (urlLen is 1) then
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
click menu item (item 1 of urls) of menu 1 of menu item "Simulator" of menu 8 of menu bar 1
end tell
end tell
end tell
else
tell application "System Events"
activate
set chooseUrl to choose from list urls with title "請選擇您的URL" default items (item 1 of urls)
end tell
if chooseUrl is not false then
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
click menu item (item 1 of chooseUrl) of menu 1 of menu item "Simulator" of menu 8 of menu bar 1
end tell
end tell
end tell
end if
end if
保存完后,自己點擊運行按鈕,看下是否可用。
如果腳本有更新,則在Automator里面,“文件->打開最近使用”選擇自己的創建的服務,然后更新下腳本即可
6)保存,command+s。輸入服務名稱:safari-simulator-debug。名字隨意自己起就好了
以上applescript & Automator配置完成
配置快捷鍵
1)打開“系統偏好設置 -> 鍵盤 -> 快捷鍵 -> 服務”
2)在右邊的列表中找到“通用 -> safari-simulator-debug”,然后點擊右邊的“添加快捷鍵”,設置成command+alt+i,和chrome打開開發者工具的快捷鍵一樣
3)打開xcode模擬器,然后打開一個webview的頁面,按下快捷鍵command+alt+i,注意:讓xcode的simulator處于活動狀態再按快捷鍵,就會執行我們剛才的applescript腳本。如果只有一個url則會自動打開該URL,如果多于1個則會讓你進行選擇需要打開的url,選擇一個URL即可。如下圖:
以上配置完成。
Q&A
1)Q:
A:
主要是因為“Xcode Simulator”沒有權限,需要把權限添加進去
權限加好以后,還會出現這種錯誤,應該是safari沒啟動起來,點擊“OK”后,再執行一遍
打開“系統偏好設置->安全性與隱私->隱私->輔助功能”加上“Xcode Simulator”,
-
由于點擊“+”的時候選擇Simulator時找不到的話可以這樣添加:
1)在圖標出右鍵,然后“選項->在Finder中顯示”
Paste_Image.png
2)把打開的圖標拖到框里面即可添加成功。
其他選項加上也可以:
接下來繼續研究怎么一鍵配置,敬請期待...
alfred workflow
已經上傳到github倉庫了