Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of file / folders scripting in OS X with Javascript
/**
* 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