代码之家  ›  专栏  ›  技术社区  ›  Monpolyme1

在AppleScriptObjC中使用Xcode中的段落

  •  0
  • Monpolyme1  · 技术社区  · 7 年前
    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)在线

    关于如何让AppleScript应用程序中的Xcode接受这个脚本,有什么想法吗?

    1 回复  |  直到 4 年前
        1
  •  0
  •   vadian    7 年前

    强迫 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 ... 线