Last active
October 1, 2018 00:25
Revisions
-
cesarandreu revised this gist
Oct 1, 2018 . 1 changed file with 12 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,22 @@ function getSelection () { return Application('Finder') .selection() .map(item => urlToPath(item.url())) .join('\n') } function getPath () { const windows = Application('Finder').windows() if (!windows.length) { throw new Error('No Finder windows open') } else { return urlToPath(windows[0].target().url()) } } function urlToPath (url) { if (!url.startsWith('file://')) { throw new Error(`Unexpected URL scheme: ${url}`) } return $.NSURL.alloc.initWithString($(url)).fileSystemRepresentation } -
cesarandreu created this gist
Oct 1, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ function getSelection () { return Application('Finder') .selection() .map(item => urlToPath(item.url())) .join('\n') } function getPath () { const windows = Application('Finder').windows() if (!windows.length) { throw new Error('No Finder windows open') } else { return urlToPath(windows[0].target().url()) } } function urlToPath (url) { if (!url.startsWith('file://')) { throw new Error(`Unexpected URL scheme: ${url}`) } return $.NSURL.alloc.initWithString($(url)).fileSystemRepresentation } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ # macOS JXA utilities * `pfd`: Return the path of the frontmost Finder window. Mnemonic: **p**rint **F**inder **d**irectory. * `pfs`: Return the current Finder selection. Mnemonic: **p**rint **F**inder **s**election. * `cdf`: cd to the current Finder directory. Mnemonic: **cd** **F**inder. ## Installation 1. Open Script Editor from `/Applications/Utilities`. 2. Create a new script and save it to `~/Library/Script Libraries` with the name `FinderUtils.scpt`. Make sure that File Format is set to Script in the save dialog. 3. Copy the contents of `FinderUtils.js` to your newly created script library. 4. Save each utility to `~/.local/bin` with permissions set to `755`. ## Notes None of these may be used remotely, they will only work locally. The `pfd` utility will fail for special views such as Recents, Computer, AirDrop, or Network. I don't know if it works with iCloud Drive. These utilities were heavily inspired by oh-my-fish's [osx plugin](github.com/oh-my-fish/plugin-osx). License: MIT. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ #!/usr/bin/env sh # cd to the current Finder directory set -e cd "$(pfd)" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ #!/usr/bin/env osascript -l JavaScript // Return the path of the frontmost Finder window Library('FinderUtils').getPath() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ #!/usr/bin/env osascript -l JavaScript // Return the current Finder selection Library("FinderUtils").getSelection()