zoukankan      html  css  js  c++  java
  • Alfred修改内置Terminal为iTerm

    用这个脚本:

    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 "iTerm.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

    参考:

    http://time-track.cn/change-terminal-to-iterm-in-alfred.html

  • 相关阅读:
    理解字节序(转)
    《逆向分析实战》数据的存储及表示形式
    C语言——内存分配
    C语言编程基础学习字符型数据的ASCII码值为何是负数?
    你知道嵌入式C语言中各变量存储的位置吗?
    stm32入门(从51过渡到32)
    说说M451例程讲解之LED
    说说M451的例程库的说明
    STM32总线结构和存储器
    STM32学习之路入门篇之指令集及cortex——m3的存储系统
  • 原文地址:https://www.cnblogs.com/EasonJim/p/8979493.html
Copyright © 2011-2022 走看看