gpt4 book ai didi

javascript - 限制 Droplet 上的文件类型

转载 作者:行者123 更新时间:2023-11-30 18:56:43 24 4
gpt4 key购买 nike

这个问题不限于懂AppleScript的人,如果你会Cocoa等,你应该知道这个问题的答案:

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?

非常感谢。

最佳答案

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

关于javascript - 限制 Droplet 上的文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1713428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com