OSX:当文件出现在文件夹执行bash脚本 [英] OSX: Execute bash script when file appears in folder
问题描述
我试图脚本我自己的截图上传
I'm attempting to script my own screenshot uploader.
我几乎有:<一href=\"http://stackoverflow.com/questions/21371254/osx-automatically-upload-screenshot-to-imagebin-and-put-url-in-clipboard\">OSX:自动上传截图imageBin,并把网址中的剪贴板
该脚本让我写:
upload_image foo.png
和它会上传,把一个链接的URL在我的剪贴板,并发出噪音
And it will upload it, put a link to the URL in my clipboard, and make a noise
但我希望它是自动的。一旦出现foo.png我的桌面上,我需要执行〜/ upload_image.sh foo.png
But I want it to be automatic. As soon as foo.png appears on my desktop, I need to execute '~/upload_image.sh foo.png'
我怎样才能做到这一点?
How can I do this?
我感兴趣的一击解决方案,它可以让我与目标脚本合并,所以我只有一个脚本文件,它是干净的。此外,它是多平台的。得到它的推出在启动时将是一个问题。
I'm interested in a Bash solution as it would allow me to merge with the target script, so I would only have one script file, which is clean. Also it would be multiplatform. Getting it to launch on start-up would be an issue.
我也有兴趣在一个AppleScript的解决方案;我想下面的脚本可能会接近:
I'm also interested in an AppleScript solution; I think the following script may be close:
on adding folder items to this_folder after receiving theFiles
-- If you want to do something with each file ...
repeat with aFile in theFiles
do shell script "~/upload_image.sh " &
end repeat
end adding folder items to
但我不知道如何通过å文件进入命令下一行。
But I don't know how to pass 'aFile' into the command on the next line.
编辑:
的http://hardc0l2e.word$p$pss.com/2012/03/13/folder-monitoring-script-using-inotifywait/
<一个href=\"http://stackoverflow.com/questions/8159472/in-a-small-script-to-monitor-a-folder-for-new-files-the-script-seems-to-be-find\">In一个小的脚本监视新文件的文件夹,该脚本似乎找到
推荐答案
您可以使用的Automator创建一个文件夹的动作:
You can use Automator to create a folder action:
,或者例如保存这个plist中为〜/库/ LaunchAgents / example.plist
:
Or for example save this plist as ~/Library/LaunchAgents/example.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>example</string>
<key>ProgramArguments</key>
<array>
<string>say</string>
<string>a</string>
</array>
<key>WatchPaths</key>
<array>
<string>~/Desktop/</string>
</array>
</dict>
</plist>
然后运行 launchctl负载〜/库/ LaunchAgents / example.plist
加载plist中。要更改应用到plist中,卸载和加载它。更多信息:
Then run launchctl load ~/Library/LaunchAgents/example.plist
to load the plist. To apply changes to the plist, unload and load it. More information:
<一个href=\"https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html\" rel=\"nofollow\">https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html
https://developer.apple.com/library/mac/technotes/tn2083 /_index.html 结果
http://osxnotes.net/launchd.html
第三种选择是使用淡褐色的:
这篇关于OSX:当文件出现在文件夹执行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!