限制对液滴的文件类型 [英] Restrict file types on droplet
本文介绍了限制对液滴的文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这问题并不局限于谁知道AppleScript的,如果你这样做可可等,你应该知道这个问题的答案的人:
我做的AppleScript中的液滴的COM presses JavaScript文件,所以很明显,我只想JavaScript文件被允许进入脚本。任何想法?
块引用>太感谢了。
解决方案属性kJavascriptExtension:JS
属性pValidFileList:{}开放theFiles的 - 打开时执行的文件被删除的脚本 集fileCount到(获得theFiles项目数) 与thisFile从1到fileCount重复
设置theFile为theFiles项目thisFile
设置theFileAlias为theFile的别名 告诉应用程序发现者
设置的fileInfo为theFileAlias信息
设置文件名对FileInfo名
告诉结束 设置javascriptFileFound我的isJavascriptFile(文件名) 如果(javascriptFileFound),然后
pValidFileList的设置结束theFile
\t万一
重复结束 显示对话框pValidFileList =&放大器; pValidFileList
- 做一些与你的文件在这里
开放式结尾在isJavascriptFile(theFilename) - (theFilename作为字符串)作为布尔
设置的AppleScript的文本项分隔符。
设置fileNameList为theFilename的每一个文本项
设置的AppleScript的文本项分隔符为 尝试
设置theFileExtension为字符串fileNameList第2项
出错
返回false
年底试 如果theFileExtension是kJavascriptExtension然后
返回true
万一 返回false
结束isJavascriptFileThis question isn't limited to people who know AppleScript, if you do Cocoa, etc., you should know the answer to this:
I'm making a droplet in AppleScript that compresses JavaScript files, so obviously, I only want JavaScript files to be allowed into the scripts. Any ideas?
Thanks so much.
解决方案property kJavascriptExtension : "js" property pValidFileList : {} on open of theFiles -- Executed when files are dropped on the script set fileCount to (get count of items in theFiles) repeat with thisFile from 1 to fileCount set theFile to item thisFile of theFiles set theFileAlias to theFile as alias tell application "Finder" set fileInfo to info for theFileAlias set fileName to name of fileInfo end tell set javascriptFileFound to isJavascriptFile(fileName) of me if (javascriptFileFound) then set end of pValidFileList to theFile end if end repeat display dialog "pValidFileList = " & pValidFileList -- do something with your files here end open on isJavascriptFile(theFilename) -- (theFilename as string) as boolean set AppleScript's text item delimiters to "." set fileNameList to every text item of theFilename set AppleScript's text item delimiters to "" try set theFileExtension to item 2 of fileNameList as string on error return false end try if theFileExtension is kJavascriptExtension then return true end if return false end isJavascriptFile
这篇关于限制对液滴的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文