alfred 与 iterm 3.x 配置

今天更新 iterm 到 3.0.4 发现 alfred 脚本不能使用了,故搜索了新的脚本,备记:

  • 设置 iterm 3.x 为 alfred shell 工具

      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.
          write_to_file(q & return, POSIX file "/tmp/alfredscript", 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 \"/tmp/alfredscript\"
              end tell
          else
              create window with default profile
              tell current session of current window
                  write contents of file \"/tmp/alfredscript\"
              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
  • 在 Finder 中打开 iterm 2.9.x ~ 3.x 当前工作目录

      on alfred_script(q)
        tell application "iTerm"
          tell the current session of current window
            write text "open -a Finder ./"
          end tell
        end tell
      end alfred_script
  • 在 iterm 2.9.x ~ 3.x 中打开 Finder 当前工作目录

      on alfred_script(q)
        tell application "Finder"
          set pathList to (quoted form of POSIX path of (folder of the front window as alias))
          set command to "clear; cd " & pathList
        end tell
        tell application "System Events"
          -- some versions might identify as "iTerm2" instead of "iTerm"
          set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
        end tell
        tell application "iTerm"
          activate
          set hasNoWindows to ((count of windows) is 0)
          if isRunning and hasNoWindows then
            create window with default profile
          end if
          select first window
          tell the first window
            if isRunning and hasNoWindows is false then
              create tab with default profile
            end if
            tell current session to write text command
          end tell
        end tell
      end alfred_script

转载于:https://www.cnblogs.com/php6/p/5697169.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值