发送所有文件在桌面上到Evernote然后删除 [英] Send all files on Desktop to Evernote then delete

查看:129
本文介绍了发送所有文件在桌面上到Evernote然后删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好

我想写我可以运行,将送我的桌面到Evernote上的所有文件,然后删除文件的AppleScript。我的code到日期是:

I am trying to write an AppleScript that I can run that will send all the files on my desktop to Evernote, and then delete the files. My code to date is:

on run {input}

tell application "Finder"
    select every file of desktop
end tell

tell application "Evernote"
    repeat with SelectedFile in input
        try
            create note from file SelectedFile notebook "Auto Import"
        end try

    end repeat

end tell

tell application "Finder"
    delete every file of desktop
end tell

end run

如果我运行这个那么第一个和最后'告诉'做工精细(即脚本凸显然后删除桌面上的所有文件),但中间'告诉'没有做任何事情。

If I run this then the first and last 'tell' work fine (ie. the script highlights then deletes all the files on the desktop), but the middle 'tell' doesn't do anything.

但是,如果我手动突出桌面上的所有文件,然后运行只是中间的'告诉',那么它导入精 - 每个项目分为按预期一个单独的说明

However, if I manually highlight all the files on the desktop and then run just the middle 'tell' then it imports fine - each item into a separate note as intended.

正如你所知道的,我是新来的AppleScript - 我怀疑我需要把选定的文件在某种类型的数组,但不能弄明白。救命啊!

As you can tell, I am new to AppleScript - I suspect I need to put the selected files in an array of some sort, but can't figure it out. Help!

非常感谢

推荐答案

因为有你的输入之间没有联系你的code失败变量和文件的选择通过查找 - 这意味着你的列表是空的,Evernote的不处理任何事情。你已经通过了尝试块包裹的Evernote导入命令没有任何错误处理,这意味着全部错误只是去忽视混淆的问题(避免这样的问题,这是很好的做法,在随时登录错误消息的错误条款,如果没有别的)。

Your code fails because there is no relation between your input variable and the selection of files via Finder – which means that your list is empty, and Evernote is not processing anything at all. You have obfuscated the problem by wrapping the Evernote import command in a try block without any error processing, which means all errors just go unnoticed (to avoid this kind of problem, it is good practice to always log the error message in an on error clause, if nothing else).

另外,你实际上并不需要通过AppleScript的选择桌面上的文件进行处理。下面code将抓住所有可见文件(不含伪文件,比如包/应用程序):

Also, you don’t actually need to select files on the Desktop via AppleScript to process them. The following code will grab all visible files (excluding pseudo-files like packages / apps):

tell application "System Events"
    set desktopFiles to every disk item of (desktop folder of user domain) whose visible is true and class is file
end tell

通过列表中,您检索的方式到Evernote进行处理:

Pass the list you retrieved that way to Evernote for processing:

repeat with aFile in desktopFiles as list
    try
        tell application "Evernote" to create note from file (aFile as alias) notebook "Auto Import"
        tell application "System Events" to delete aFile
    on error errorMessage
        log errorMessage
    end try
end repeat

和你是好去。

请注意,通过明智地将删除命令(导入命令之后,try块内,循环在所有文件中),你要确保,如果Evernote的没有错误的进口,同时避免不必重复它只是叫在文件几次。

Note that by judiciously placing the deletion command (right after the import command, inside the try block, inside the loop over all files), you make sure it is only called if Evernote does not error on import while avoiding having to iterate over the files several times.

最后请注意:你不必使用块语法告诉语句如果只需要一个命令来执行 - 使用告诉<目标>到<命令方式> 更容易,将让你出嵌套的背景下地狱

A final note: you don’t have to use the block syntax for tell statements if there is only one command to execute – using tell <target> to <command> is easier and will keep you out of nested context hell.

感谢@adayzone对列表的处理和别名强制更正

这篇关于发送所有文件在桌面上到Evernote然后删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆