1

I have used Automator to create an app bundle that activates an app ("Fuse") within the Resources directory of the bundle, which then opens the file "Exolon.tzx" (also located in Resources).

However, I can only get this to work when pointing to the full location of "Exolon.tzx" while the app is on my Desktop. Obviously, when I move the app it no longer works.

What do I need to change in this script to have it point to and open "Exolon.tzx" regardless of where I keep the app (in particular, I want it to work when I transfer the app to another Mac).

My script:

tell application "Fuse"
        open POSIX file "/Users/almeath/Desktop/Exolon.app/Contents/Resources/Exolon.tzx"
    end tell
    tell application "System Events"
        set frontmost of process "Fuse" to true
    end tell
    tell application "System Events"
        keystroke "f" using command down
    end tell

When I run the app from the Desktop it activates the Fuse app, opens Exolon.tzx and then executes the specified keystroke. If I move the app to another location (i.e not the Desktop) then an error is produced: “The action Run AppleScript encountered an error: “Fuse got an error: Connection is invalid”

3
  • 1
    Welcome to Ask Different. What specifically is “does not work”? What is the end result when this works as well?
    – bmike
    Commented Apr 20, 2019 at 19:37
  • When I run the app from the Desktop it activates the Fuse app, opens Exolon.tzx and then executes the specified keystroke. If I move the app to another location (i.e not the Desktop) then an error is produced: “The action Run AppleScript encountered an error: “Fuse got an error: Connection is invalid”
    – almeath
    Commented Apr 20, 2019 at 19:56
  • 1
    Your posix file is likely the first error. Please consider editing your post so it has everything needed to answer. Comments are ephemeral and go away on occasion.
    – bmike
    Commented Apr 20, 2019 at 20:28

2 Answers 2

1

You can use path to resource to get the pathname of the file that's in an App's Resource folder.

Example AppleScript code:

set resourceName to "Exolon.tzx"

set filePathName to quoted form of POSIX path of (path to resource resourceName) as text

tell application "Fuse"
        open POSIX file filePathName
end tell

Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.

2
  • Thank you for that advice. Your example above seems to work for me, but only partially. The Fuse application will load, but for some reason it will not open the file "Exolon.tzx". Fuse just loads as normal and then does nothing else. I know the script is calling the file in the correct location, because if I remove "Exolon.tzx" from the Resources folder, the script will produce a "resource not found" error. I know the "Exolon.tzx" file is not the problem either, because I can switch it with a different tzx file and the same thing happens.
    – almeath
    Commented Apr 21, 2019 at 14:02
  • What I find confusing is that Fuse will open the Exolon.tzx file in my original script, with the full POSIX link. While the example code above does not produce an error when I run it, something is stopping Fuse from recognizing it as a command to open the tzx file. But with no error produced, it is very hard to understand why the problem is occuring.
    – almeath
    Commented Apr 21, 2019 at 14:36
-1
tell application "Fuse"
    open POSIX file "/Users/almeath/Desktop/Exolon.app/Contents/Resources/Exolon.tzx"
end tell

tell application "System Events"
    set frontmost of process "Fuse" to true
end tell

tell application "System Events"
    keystroke "f" using command down
end tell
1
  • Not sure how you expect just copying the code exactly as it is in the OP and posting it as an answer answers the question! Commented Apr 21, 2019 at 9:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .