문제

이 질문은 AppleScript를 아는 사람들에게만 국한되지 않습니다. 코코아 등을하는 등에 대한 답을 알아야합니다.

JavaScript 파일을 압축하는 AppleScript에서 액적을 만들고 있으므로 분명히 JavaScript 파일 만 스크립트에 허용되기를 원합니다. 어떤 아이디어?

정말 고마워.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top