Skip to content

iron2column/alfred-iterm2-cd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

alfred-iterm2-cd

This is a workflow script of Alfred based on Applescript.


1. Introduce

You can call Alfred, and then enter cd "your target file or directory". After entering, it will create a new iterm2 window and switch to the target file or directory.

2. Script

set thePath to "{query}"

set result to do shell script "file -b " & thePath

if result is not equal to "directory" then
	set q to characters 1 thru -((offset of "/" in (reverse of items of thePath as string)) + 1) of thePath as string
else
	set q to thePath
end if

set q to "cd " &q &" && clear"

if application "iTerm" is running then
	run script "
			on run {q}
				tell application \"iTerm\"
					tell the first window
						create window with default profile
						tell current session to write text q 
					end tell
				end tell
			end run
		" with parameters {q}
else
	run script "
			on run {q}
				tell application \"iTerm\"
					activate
					delay 0.5
					tell application \"iTerm\"
					tell the first window
						tell current session to write text q 
					end tell
					end tell
				end tell
			end run
		" with parameters {q}
end if

About

This is a workflow script of Alfred based on Applescript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published