Skip to content

Instantly share code, notes, and snippets.

@kazuma0129
Last active January 19, 2023 08:05
Show Gist options
  • Save kazuma0129/f47382f09d7d997b1dbbe2b95678a211 to your computer and use it in GitHub Desktop.
Save kazuma0129/f47382f09d7d997b1dbbe2b95678a211 to your computer and use it in GitHub Desktop.
Japanese version of a script that automatically launches the safari inspector of the iOS simulator
-- `menu_click`, by Jacob Rus, September 2006.
-- Ref: https://stackoverflow.com/questions/14669542/automatically-open-the-safari-debugger-when-the-iphone-simulator-is-launched
on find_by(arr, str)
repeat with elm in arr
if str contains elm then
return str
else
return null
end if
end repeat
end find_by
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
-- Find Simulator entry
global simulatorValue
activate application "Safari"
tell application "System Events"
tell process "Safari"
set menuItemList to name of every menu item of menu "開発" of menu bar 1
repeat with menuItem in menuItemList
if menuItem contains "シミュレータ" then
set simulatorValue to menuItem
end if
end repeat
end tell
end tell
delay 0.3
-- Find webview entry inside Simulator
global menuValue
global allowList
set allowList to {"me", "localhost", "127.0.0.1"}
activate application "Safari"
tell application "System Events"
tell process "Safari"
set menuItemList to name of every menu item of menu simulatorValue of menu item simulatorValue of menu "開発" of menu bar 1
set tmp to null
repeat with menuItem in menuItemList
set tmp to my find_by(allowList, menuItem)
if tmp ≠ null then
set menuValue to tmp
end if
end repeat
end tell
end tell
menu_click({"Safari", "開発", simulatorValue, menuValue})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment