Skip to content

Instantly share code, notes, and snippets.

@takuya
Created May 10, 2017 05:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuya/2529b35d8cc6140c69975dcea653ea29 to your computer and use it in GitHub Desktop.
Save takuya/2529b35d8cc6140c69975dcea653ea29 to your computer and use it in GitHub Desktop.
#!/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