forklift.plugin.zsh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. try
  28. tell application "Finder"
  29. set forkLiftSetapp to name of application file id "com.binarynights.forklift-setapp"
  30. end tell
  31. on error err_msg number err_num
  32. set forkLiftSetapp to null
  33. end try
  34. try
  35. tell application "Finder"
  36. set forkLift3 to name of application file id "com.binarynights.ForkLift-3"
  37. end tell
  38. on error err_msg number err_num
  39. set forkLift3 to null
  40. end try
  41. try
  42. tell application "Finder"
  43. set forkLift2 to name of application file id "com.binarynights.ForkLift2"
  44. end tell
  45. on error err_msg number err_num
  46. set forkLift2 to null
  47. end try
  48. try
  49. tell application "Finder"
  50. set forkLift to name of application file id "com.binarynights.ForkLift"
  51. end tell
  52. on error err_msg number err_num
  53. set forkLift to null
  54. end try
  55. if forkLiftSetapp is not null and application forkLiftSetapp is running then
  56. tell application forkLiftSetapp
  57. activate
  58. set forkLiftVersion to version
  59. end tell
  60. else if forkLift3 is not null and application forkLift3 is running then
  61. tell application forkLift3
  62. activate
  63. set forkLiftVersion to version
  64. end tell
  65. else if forkLift2 is not null and application forkLift2 is running then
  66. tell application forkLift2
  67. activate
  68. set forkLiftVersion to version
  69. end tell
  70. else if forkLift is not null and application forkLift is running then
  71. tell application forkLift
  72. activate
  73. set forkLiftVersion to version
  74. end tell
  75. else
  76. if forkLiftSetapp is not null then
  77. set appName to forkLiftSetapp
  78. else if forkLift3 is not null then
  79. set appName to forkLift3
  80. else if forkLift2 is not null then
  81. set appName to forkLift2
  82. else if forkLift is not null then
  83. set appName to forkLift
  84. end if
  85. tell application appName
  86. activate
  87. set forkLiftVersion to version
  88. end tell
  89. repeat until application appName is running
  90. delay 1
  91. end repeat
  92. tell application appName
  93. activate
  94. end tell
  95. end if
  96. tell application "System Events"
  97. tell application process "ForkLift"
  98. try
  99. set topWindow to window 1
  100. on error
  101. keystroke "n" using command down
  102. set topWindow to window 1
  103. end try
  104. keystroke "g" using {command down, shift down}
  105. if forkLiftVersion starts with "3" then
  106. tell pop over of list of group of splitter group of splitter group of topWindow
  107. set value of text field 1 to "$PWD"
  108. end tell
  109. else
  110. tell sheet 1 of topWindow
  111. set value of text field 1 to "$PWD"
  112. end tell
  113. end if
  114. keystroke return
  115. end tell
  116. end tell
  117. END
  118. }