alfred使用iterm2会打开两个窗口,怎么改成一个

发布于 2022-09-05 06:14:41 字数 2622 浏览 23 评论 0

on write_to_file(this_data, target_file, append_data)
    try
        set the target_file to the target_file as string
        set the open_target_file to open for access file target_file with write permission
        if append_data is false then set eof of the open_target_file to 0
        write this_data to the open_target_file starting at eof
        close access the open_target_file
        return true
    on error
        try
            close access file target_file
        end try
        return false
    end try
end write_to_file


on alfred_script(q)
    
    -- Write the command to run to a file. This is done because Applescript quoting is impossible to get right, esp. for backslashes.
    set tmp_dir to path to temporary items as string from user domain
    set applescript_alfred_file to tmp_dir & "alfredscript"
    set alfred_file to POSIX path of applescript_alfred_file
    write_to_file(q & return, applescript_alfred_file, false)
    
    -- Create this file, which prevents iTerm2 from restoring a saved window arrangement.
    do shell script "touch ~/Library/Application' Support/iTerm/quiet'"
    
    -- Test cases:
    -- 1. iTerm2 running, has windows open. Should open a new window for Alfred command.
    -- 2. iTerm2 running, no windows open. Should open a new window for Alfred command.
    -- 3. iTerm2 not running, set to restores arrangement. Should not restore arrangement but open a new window for the Afred command.
    -- 4. iTerm2 not running. No windows to restore. Should open a single window for the Alfred command.
    -- 5. iTerm2 not running. Has windows to restore. Restores windows and then opens a new window for the Alfred command.
    
    -- Compose a script. This is necessary because compiling in a 'tell application' command causes the app to be launched, which would happen prior to the creation of the quiet file.
    set theScript to "tell application \"iTerm2.app\"
    if (exists current window) then
        tell current window to create tab with default profile
        tell current session of current window
            write contents of file \"" & alfred_file & "\"
        end tell
    else
        create window with default profile
        tell current session of current window
            write contents of file \"" & alfred_file & "\"
        end tell
    end if
    activate
end tell"
    
    -- Invoke the script.
    run script theScript
    
    -- Clean up
--    do shell script "rm -f ~/Library/Application' Support/iTerm/quiet' /tmp/alfredscript"
end alfred_script

这是官方的代码,应该怎么修改?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放肆 2022-09-12 06:14:41
    tell current window to create tab with default profile

这行代码删除即可。

彩扇题诗 2022-09-12 06:14:41

参照 https://github.com/stuartcrya... 解决问题

官方的是V3版,现在还未出来。只有 2.9 吧。你用一下 2.9 的试试。

打开这个地址可得到
https://raw.githubusercontent...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文