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