Applescript indicates resource not found when trying to call within inside the app

橙三吉。 提交于 2020-01-06 15:28:06

问题


Playing with AppleScript I am confused on what I am doing wrong when I try to call another AppleScript from the Scripts folder. My current script is saved as foo.app and I see the structure from the Bundle Contents but when I try to call bar.app from inside the Scripts folder I get a dialog of Resource not found.

After referencing "How to access from AppleScript a bundled file within a Cocoa-AppleScript Application?" I tried:

tell application "Finder"
    set thisFolder to (container of (path to me)) as string
    set insideApp to thisFolder & (path to resource "bar.app")
end tell

When that produced the error I did some more searching I referenced "How do I get the Scripts folder in the application bundle?" and tried:

tell application "Finder"
    set thisFolder to (container of (path to me)) as string
    set insideApp to (thisFolder as alias) & (path to resource "bar.app" in directory "Scripts")
end tell

Targeting description.rtfd I display the variable thisFolder and the dialog I get Macintosh HD:Users:darth_vader:Desktop: but it produces Resource not found when I run:

tell application "Finder"
    set thisFolder to (container of (path to me)) as string
    display dialog thisFolder
    set insideApp to thisFolder & (path to resource "Contents:Resources:description.rtfd")
end tell

What exactly am I doing wrong and how do I call from within the Scripts folder?


回答1:


There is a general misunderstanding:

path to me points to the path to the script (bundle).
container of (path to me) points to the path to the enclosing folder of the script (bundle)

So it's:

set insideApp to path to resource "bar.app"

or:

set insideApp to path to resource "bar.app" in directory "Scripts"

or (preferable)

set insideApp to alias ((path to me as text) & "Contents:Resources:description.rtfd")

The Finder is not needed at all.



来源:https://stackoverflow.com/questions/35490886/applescript-indicates-resource-not-found-when-trying-to-call-within-inside-the-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!