在 AppleScriptObjC 中使用 Xcode 中的段落
using Paragraphs in Xcode in AppleScriptObjC
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:]: Can’t make current application into type file. (error -1700) on the line
set sampleFiles to paragraphs of (read POSIX file (POSIX path of homeFolder & "/Documents/sampleBuilds.txt"))
关于如何让 AppleScript 应用程序 Xcode 接受这个脚本有什么想法吗?
无需对 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 ...
行。
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:]: Can’t make current application into type file. (error -1700) on the line
set sampleFiles to paragraphs of (read POSIX file (POSIX path of homeFolder & "/Documents/sampleBuilds.txt"))
关于如何让 AppleScript 应用程序 Xcode 接受这个脚本有什么想法吗?
无需对 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 ...
行。