Parent directory

forklift.plugin.zsh

3805 bytes
  1# Open folder in ForkLift.app or ForkLift2.app from console
  2# Author: Adam Strzelecki nanoant.com, modified by Bodo Tasche bitboxer.de
  3#         Updated to support ForkLift 2 and ForkLift 3 by Johan Kaving
  4#         Updated to support ForkLift from Setapp by Paul Rudkin
  5#         Updated to support ForkLift 4 by Michal Szymanski (misiektoja)
  6#
  7# Usage:
  8#   fl [<folder>]
  9#
 10# Opens specified directory or current working directory in ForkLift.app
 11#
 12# Notes:
 13# It assumes Shift+Cmd+G launches go to folder panel and Cmd+N opens new
 14# app window.
 15#
 16# https://gist.github.com/3313481
 17function fl {
 18  if [ ! -z "$1" ]; then
 19    DIR=$1
 20    if [ ! -d "$DIR" ]; then
 21      DIR=$(dirname $DIR)
 22    fi
 23    if [ "$DIR" != "." ]; then
 24      PWD=`cd "$DIR";pwd`
 25    fi
 26  fi
 27  osascript 2>&1 1>/dev/null <<END
 28
 29  try
 30    tell application "Finder"
 31        set forkLiftSetapp to name of application file id "com.binarynights.forklift-setapp"
 32    end tell
 33  on error err_msg number err_num
 34    set forkLiftSetapp to null
 35  end try
 36  try
 37    tell application "Finder"
 38        set forkLift3 to name of application file id "com.binarynights.ForkLift-3"
 39    end tell
 40  on error err_msg number err_num
 41    set forkLift3 to null
 42  end try
 43  try
 44    tell application "Finder"
 45        set forkLift2 to name of application file id "com.binarynights.ForkLift2"
 46    end tell
 47  on error err_msg number err_num
 48    set forkLift2 to null
 49  end try
 50  try
 51    tell application "Finder"
 52        set forkLift to name of application file id "com.binarynights.ForkLift"
 53    end tell
 54  on error err_msg number err_num
 55    set forkLift to null
 56  end try
 57
 58  if forkLiftSetapp is not null and application forkLiftSetapp is running then
 59    tell application forkLiftSetapp
 60        activate
 61        set forkLiftVersion to version
 62    end tell
 63  else if forkLift3 is not null and application forkLift3 is running then
 64    tell application forkLift3
 65        activate
 66        set forkLiftVersion to version
 67    end tell
 68  else if forkLift2 is not null and application forkLift2 is running then
 69    tell application forkLift2
 70        activate
 71        set forkLiftVersion to version
 72    end tell
 73  else if forkLift is not null and application forkLift is running then
 74    tell application forkLift
 75        activate
 76        set forkLiftVersion to version
 77    end tell
 78  else
 79    if forkLiftSetapp is not null then
 80        set appName to forkLiftSetapp
 81    else if forkLift3 is not null then
 82        set appName to forkLift3
 83    else if forkLift2 is not null then
 84        set appName to forkLift2
 85    else if forkLift is not null then
 86        set appName to forkLift
 87    end if
 88
 89    tell application appName
 90        activate
 91        set forkLiftVersion to version
 92    end tell
 93    repeat until application appName is running
 94        delay 1
 95    end repeat
 96    tell application appName
 97        activate
 98    end tell
 99  end if
100
101  tell application "System Events"
102    tell application process "ForkLift"
103        try
104            set topWindow to window 1
105        on error
106            keystroke "n" using command down
107            set topWindow to window 1
108        end try
109        keystroke "g" using {command down, shift down}
110        if forkLiftVersion starts with "3" then
111            tell pop over of list of group of splitter group of splitter group of topWindow
112                set value of text field 1 to "$PWD"
113            end tell
114        else if forkLiftVersion starts with "4" then
115            tell pop over of list of group of splitter group of splitter group of topWindow
116                keystroke "$PWD"
117                delay 0.1
118            end tell
119        else
120            tell sheet 1 of topWindow
121                set value of text field 1 to "$PWD"
122            end tell
123        end if
124        keystroke return
125    end tell
126  end tell
127END
128}