Skip to content

Instantly share code, notes, and snippets.

@elentok
Created August 13, 2013 07:47
Show Gist options
  • Save elentok/6218781 to your computer and use it in GitHub Desktop.
Save elentok/6218781 to your computer and use it in GitHub Desktop.
Open forklift from terminal
#!/bin/bash
# Open current directory in forklift
echo -n $PWD | pbcopy
(cat<<EOF
tell application "Forklift"
activate
tell application "System Events"
keystroke "G" using {command down}
keystroke "v" using {command down}
keystroke return
keystroke return
end tell
end tell
EOF
) | osascript
@fvsch
Copy link

fvsch commented Aug 21, 2013

Thanks for this script. I did a few modifications on my side:

  • I updated the echo line to use it in Automator (for creating a Service to launch from Finder).
  • I fixed and possibly improved the AppleScript.
#!/bin/bash
# Open current directory in forklift
# Adapted from https://gist.github.com/elentok/6218781

echo -n $@ | pbcopy

(cat<<EOF

if application "ForkLift" is not running then
    # This will launch Forklift if it's not running
    # (But it's not making it the frontmost/focused application)
    activate application "ForkLift"
    # We wait 1 second so that we're pretty sure ForkLift did launch
    delay 1
end if

# Give focus to ForkLift
activate application "ForkLift"
set canOpenTab to "unknown"

tell application "System Events"
    tell process "ForkLift"
        # Open new window if none, or new tab if there is one open
        set canOpenTab to enabled of menu item 2 of menu 1 of menu bar item "File" of menu bar 1
        if canOpenTab is true then
            keystroke "t" using {command down}
        else
            keystroke "n" using {command down}
        end if
        # Using ForkLift's "Go to Folder"
        keystroke "g" using {command down, shift down}
        keystroke "v" using {command down}
        keystroke return
    end tell
end tell

EOF
) | osascript

@McNull
Copy link

McNull commented Mar 26, 2014

I've made two small changes:

  • optional path argument
  • does not use the clipboard anymore

Fork can be found here: https://gist.github.com/McNull/9779719

Thank you both for sharing!

@Jobbies
Copy link

Jobbies commented May 25, 2018

You could use open -a Forklift . which opens the current folder in forklift.

@ApolloTang
Copy link

In case you are having the same problem as I have:

Solved this this error:

Script Editor:
System Events got an error: Script Editor is not allowed to send keystrokes.

Need to add some (or all) of the following 'Security & Privacy' setting:

Goto:
  System Preferences -> Security & Privacy -> Accessibility
  System Preferences -> Security & Privacy -> Input Monitoring
Add:
  /System/Applications/Utilities/Script Editor.app
  /System/Library/CoreServices/AppleScript Utility
  /System/Library/CoreServices/System Events.app
  /usr/local/bin/bash
  /Applications/Setapp/ForkLift.app

Reference:
https://apple.stackexchange.com/questions/394275/com-automator-runner-xpc-is-not-allowed-to-send-keystrokes#
https://apple.stackexchange.com/questions/291574/osascript-is-not-allowed-assistive-access-1728

tags:
applescript-keystroke-permission

@therealmarv
Copy link

just in case somebody needs an updated version for Forklift 4.x

look here https://gist.github.com/therealmarv/4d6442593261e2776d75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment