rkanter / Open-iTerm-or-Terminal-Here...

Generates an Applescript app that you can put in your Finder toolbar which will open an iTerm or Terminal tab at the current directory.
MIT License
134 stars 17 forks source link

Create a new window instead of a tab? #3

Open jasonfharris opened 4 years ago

jasonfharris commented 4 years ago

It would be nice to have the option to always create a new window instead of a new tab.

I changed the AppleScript slightly to allow this:

tell application "Finder"
    if (count of windows) > 0 then
        set thePath to target of front window
    else
        display dialog "There are no open Finder windows." with icon caution buttons {"OK"} with title "Open iTerm Here..."
        return
    end if
end tell

if not (exists thePath) then
    tell application "Finder" to set theName to name of front window
    display dialog "The location of the Finder window \"" & theName & "\" is not a real location (e.g. smart folder, search, network, trash, etc) and cannot opened in iTerm." with icon caution buttons {"OK"} with title "Open iTerm Here..."
    return
end if
set thePath to quoted form of POSIX path of (thePath as alias)

tell application "iTerm"
    -- Handles the case where iTerm is running but has no windows
    set createdWindow to false
    create window with default profile

    tell current session of current window
        write text "cd " & thePath & " && clear"
    end tell

    activate
end tell

And this works for me, but likely this should be packaged up as an option to the generation script...?

rkanter commented 4 years ago

That's a good idea. My workflow is to always a use a new tab, so that's what it does; but I can understand that some people might typically use windows instead of tabs. I'll try to look into this at some point, but it might be a while.