在AppleScriptObjC中使用Xcode中的Paragraphs

时间:2017-07-26 23:30:30

标签: xcode applescript applescript-objc paragraphs

do shell script "mdfind kMDItemCFBundleIdentifier = com.test.sample > ~/Documents/sampleBuilds.txt"
set homeFolder to (path to home folder)
set sampleFiles to paragraphs of (read POSIX file (POSIX path of homeFolder & "/Documents/sampleBuilds.txt"))

if (count of sampleFiles) is 0 then
    display notification "No Sample builds are present on the system"
else
    set sampleFiles to paragraphs of (read POSIX file (POSIX path of homeFolder & "/Documents/sampleBuilds.txt"))                
    display dialog "You have " & (count of sampleFiles) & " build(s) of Sample on your system. Would you like to remove them all? This cannot be undone"

    repeat with c in SampleFiles
        do shell script "rm -rf " & (quoted form of c)
        display notification "Sample build located at " & c & " has been removed from your system"
    end repeat

    do shell script "rm -rf ~/Documents/SampleBuilds.txt"
end if

当使用正确的发件人将脚本放入Xcode时,我收到错误:

  

[AppDelegate testScript:]:无法将当前应用程序转换为类型文件。 (错误-1700)

行      

将sampleFiles设置为段落(读取POSIX文件(homeFolder&“/ Files / sampleBuilds.txt”的POSIX路径))

有关如何在AppleScript应用程序中获取Xcode以接受此脚本的任何想法?

1 个答案:

答案 0 :(得分:0)

不需要强制POSIX file解决问题。

set sampleFiles to paragraphs of (read (POSIX path of homeFolder & "/Documents/sampleBuilds.txt"))

AppleScriptObjC POSIX file foo基本上不起作用,你必须写foo as POSIX file

旁注:

两次阅读文本是多余的。您可以删除第二个set sampleFiles to ...行。