Created
December 28, 2014 11:58
-
-
Save ofstudio/ab75d15ca2824fb4a85e to your computer and use it in GitHub Desktop.
Example of file / folders scripting in OS X with Javascript
This file contains 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 characters
/** | |
* Example of file / folders scripting in OS X with Javascript | |
* Open /Applications/Script Editor.app, paste the code and click Run button | |
* | |
* @author Oleg Fomin <ofstudio@gmail.com> | |
* | |
*/ | |
function file_exists(name) { | |
try { | |
return Application('System Events').files.byName(name).exists() | |
} catch (e) { | |
return false; | |
} | |
} | |
function folder_exists(name) { | |
try { | |
return Application('System Events').folders.byName(name).exists() | |
} catch (e) { | |
return false; | |
} | |
} | |
file_exists('~/Desktop/exists.txt'); // true | |
file_exists('~/Desktop/no-exists.txt'); // false | |
folder_exists('/Library'); // true | |
folder_exists('/somethingelse'); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment