This guide provides step-by-step instructions on how to create two Quick Actions in Finder:
- Open the current folder in iTerm2
- Create a new file in the current folder
These actions can be triggered using keyboard shortcuts for quick and easy access.
Follow these steps to create a Quick Action that opens the current folder in iTerm2:
-
Open Automator: You can find it in your Applications folder or search for it in Spotlight.
-
Create a New Document: Click on "New Document" and then select "Quick Action". Click "Choose".
-
Set Workflow Input: Set the "Workflow receives" dropdown to "no input".
-
Add AppleScript Action: In the left panel, find "Run AppleScript" and drag it to the right panel.
-
Enter AppleScript Code: Replace the default AppleScript code with the following:
try
tell application "Finder" to set this_folder ¬
to (folder of the front window) as alias
on error -- no open folder windows
set this_folder to path to desktop folder as alias
end try
tell application "iTerm"
if it is running then
tell current window
create tab with default profile
tell current session
write text "cd " & quoted form of POSIX path of this_folder
end tell
end tell
else
activate
tell current window
tell current session
write text "cd " & quoted form of POSIX path of this_folder
end tell
end tell
end if
end tell- Save the Workflow: Save the workflow with a name like "Open iTerm Here".
-
Open System Preferences: Go to System Preferences -> Keyboard -> Shortcuts -> Services.
-
Find the Service: Scroll down until you find the Service "Open iTerm Here" under the "General" section.
-
Add Shortcut: Click on the "none" text on the right side of "Open iTerm Here", which will change to "Add Shortcut".
-
Set Shortcut: Press the keys you want to use as a shortcut, for example, ⌘ Command + ⌥ Option + T.
Now, when you press your chosen shortcut, iTerm2 will open in the current folder or the Desktop folder if no Finder window is open.
Follow the same steps as above, but replace the AppleScript code with the following and save the workflow as "Create New File":
try
tell application "Finder" to set the this_folder ¬
to (folder of the front window) as alias
on error -- no open folder windows
set the this_folder to path to desktop folder as alias
end try
set thefilename to text returned of (display dialog ¬
"Create file named:" default answer "filename.txt")
set thefullpath to POSIX path of this_folder & thefilename
do shell script "touch \"" & thefullpath & "\""For the keyboard shortcut, you might use ⌘ Command + ⌥ Option + N.
Note: The keyboard shortcuts mentioned in this document are just examples. You can choose any combination that suits your needs and is not already in use by the system.