Code Monkey home page Code Monkey logo

mac's Introduction

mac

Mac os X 使用小技巧

mac's People

Contributors

zhuangjinxin avatar

mac's Issues

Alfred Workflows: www.alfredworkflow.com

Alfred Workflow 合集:http://www.alfredworkflow.com
GiHub:https://github.com/hzlzh/AlfredWorkflow.com
感觉发现了新大陆,好多实用的东东!

Alfred框把默认终端变为iTerm2

Alfred->Features->Terminal/shell
Application栏选择:Custom
Application Script 填写:

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

在Alfred框中输入:> ls
即可调起iTerm终端,并执行命令。

iTerm Version3官网:https://www.iterm2.com/version3.html
iTerm2 3.0 Alfred Script:https://gist.githubusercontent.com/gnachman/4cbe6743baa7fe07536b/raw/61fceba4a0b2624850ac1b4a20ac8ca48e07f7d2/gistfile1.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.