iphone - iPhone 模拟器启动时自动打开 Safari 调试器

标签 iphone xcode safari automator

Safari 中的 iOS Web 调试器非常出色,但每次模拟器重新启动时它都会关闭。每次构建后从菜单中重新打开它不仅很烦人,而且使调试启动期间发生的任何行为变得很棘手。

有没有办法在 Xcode 中设置触发器,以便在每次构建后自动打开 Safari 调试器,或者可以构建 shell 脚本或 Automator 操作来执行构建并立即打开调试器?

最佳答案

这是部分解决方案。这样可以一键打开 Safari 的调试窗口,效果好很多,但不是自动的。

在 Mac 上打开脚本编辑器(Command + 空格键并在脚本编辑器中键入)

粘贴此代码:

-- `menu_click`, by Jacob Rus, September 2006
-- 
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item.  In this case, assuming the Finder 
-- is the active application, arranging the frontmost folder by date.

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

menu_click({"Safari", "Develop", "Simulator", "index.html"})

模拟器打开后,单击脚本上的“运行”(您可能需要第一次在设置中允许脚本编辑器)。

(可选)您可以将脚本保存为应用程序,这样您就不必打开脚本编辑器。

关于iphone - iPhone 模拟器启动时自动打开 Safari 调试器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14669542/

相关文章:

Xcode 创建新文件夹/组快捷方式?

python - 解决 Safari 中 Webdriver 缺乏交互 API 的问题

html 代码在 chrome 和 safari 中执行不同

iphone - 从 CMSampleBufferRef 创建的 UIImage 未显示在 UIImageView 中?

ios - 快速折叠一行上的 tableView 行选择

iphone - 从相机和相机胶卷加载和保存图像时出现问题。我究竟做错了什么?

ssl - Safari 在使用 HTTP/2 时无法给出响应

iphone - 将富文本内容显示为 UIWebView 或 UILabel+CoreText

Xcode 无法从嵌入式框架中找到 header

ios - XCode:UIWebView 邮件链接不工作?