Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env osascript -l JavaScript
ObjC.import('stdlib')
ObjC.import('Cocoa')
function create_note_attachment( file_path ){
nsStr = $.NSString.alloc.initWithUTF8String(file_path);
name = nsStr.lastPathComponent.UTF8String;
file_path = nsStr.stringByStandardizingPath.UTF8String;
var app = Application("Evernote")
var notebooks = app.notebooks
var defautNoteBook = Array.apply(null, notebooks).find(function(e){ return e.default })
var note = app. createNote({
title: name,
notebook: defautNoteBook,
withText : name
})
note.append({ attachment: Path(file_path) })
app.activate()
$.exit(0)
}
//コマンドライン引数を取る
function run( argv ){
mgr = $.NSFileManager.defaultManager;
ns_str = $.NSString.alloc.init;
argv = Array.apply(null,argv).filter(function(e){
var isDir= Ref();
mgr.fileExistsAtPathIsDirectory(e,isDir)
return mgr.fileExistsAtPath(e) && !isDir[0]
})
if ( argv == undefined || argv.length < 1 ) {
console.log("./files_to_evernote [FILE...]")
console.log("\t -h このファイル")
console.log("\t使い方 Evernote.app に引数で指定したファイルを送信")
$.exit(0)
}
argv.forEach(function(e){
create_note_attachment(e)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment