2014-03-25 52 views
2

以下applescript将AppUninstaller.scpt注册为文件夹操作到垃圾文件夹。 注册文件夹操作脚本在Mac OSX 10.7和10.8中正常工作。applescript(10.9)无法将别名转换为类型说明符

在10.9,我得到的错误“连接错误系统事件得到了一个错误:不能使别名的‘Macintosh HD:用户:[用户名] :.垃圾桶:’到类型说明符

错误而在执行该语句

attach action to _trashFolder using _uninstallerScriptPath 

完整的脚本如下发生。在误差

on run 
    tell utils 

     init() 
     registerFolderAction() 

    end tell 
end run 


script utils 
     property _uninstallerScript : "AppUninstaller.scpt" 
     property _resRelativePath : ":Applications:TestDemo.app:Contents:Resources:" 
     property _folderActionScriptRelativePath : "Scripts:Folder Action Scripts" 

     global _resPath 
     global _trashFolder 
     global _uninstallerScriptPath 

     on init() 
        -- Setup paths 
       set _trashFolder to path to trash folder 

       set _uninstallerScriptPath to getUninstallerScript() 

        -- Add boot disk name to App relative path 
       tell application "Finder" 
          set startupDisk to (name of startup disk) 
          set _resPath to startupDisk & _resRelativePath 
       end tell 

       set scriptFolderPath to getScriptPath() 

      -- Copy folder action script file from appbundle to scripts folder 
      copyScript() 

     end init 

     on registerFolderAction() 
       try 
        tell application "System Events" 
          set folder actions enabled to true 
          log _uninstallerScriptPath 

          -- problem with below statement. 
          attach action to _trashFolder using _uninstallerScriptPath 

          end tell 
       on error msg 
          display dialog "Attach error " & msg 
       end try 

     end registerFolderAction 

     on getScriptPath() 
       return ((path to library folder from user domain) as string) & _folderActionScriptRelativePath 
     end getScriptPath 

     on getUninstallerScript() 
       return getScriptPath() & ":" & _uninstallerScript 
     end getUninstallerScript 

     -- copying the script inside app bundle into scripts folder. 
     on copyScript() 
       tell application "Finder" 
          set srcFile to _resPath & _uninstallerScript 
          set dstFile to my getScriptPath() 

          log "Src File " & srcFile & " dstFolder " & dstFile 
          duplicate file srcFile to dstFile with replacing 
       end tell 
     end copyScript 

end script 

回答

2

展望(和测试自己之后)似乎在预小牛系统attach action to命令的第一个参数是否正确强制转换为文件/文件夹对象说明符当参数是一个别名。在Mavericks中,这种强制不会发生,并且会发生错误,因为给定的参数不是对象/类型说明符而是别名类。 attach action to的第一个参数需要是一个对象/类型说明符,因此您可以通过在调用该命令时强制强制来解决您的问题。

attach action to folder (_trashFolder as text) using _uninstallerScriptPath 

你可以做同样的说法using

+0

感谢DJ试听!这帮助我解决了这个问题:) – VS7

+0

不客气。你可以标记这个答案是正确的吗?不仅仅针对我的观点,在概述中,其他人会看到这个问题已经得到解答(答案的数量是黄色的)。 –

相关问题