forklift.plugin.zsh 2.9 KB

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