Monday, September 1, 2014

#1 2012-04-07 02:38:24 pm

vrttsllvn
Member
Registered: 2012-01-26
Posts: 6

Error opening script as application

I know enough about Applescript to write everything I need to with enough efficiency to get my application running. My problem is when I save as an application. I want to "package" my script as an application that I can open up on another computer and run. But when I run the application on a different computer, it wants to search for an icon that I have built into the application that isn't lead to by the written path within my script. Here is the error:

File file MacintoshHD:Users:Everett:Desktop:Scheduling:Scheduling_icon.icns wasn't found

Is there a way to "package" all of this information into my script/application? Or will I have to do without the graphics to run it on a different machine.

I know this is probably an amateurish question but it's the last thing standing in the way of me completing this project.


Filed under: Application, icon, Error, package

Offline

 

#2 2012-04-07 02:42:28 pm

vrttsllvn
Member
Registered: 2012-01-26
Posts: 6

Re: Error opening script as application

Oh also I've read to just "Save As" an "Application Bundle" but I don't have that option in "Save As", only "Save As" "Application".

Offline

 

#3 2012-04-07 02:52:07 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10490
Website

Re: Error opening script as application

Hi,

you can save a script as application bundle (in 10.7 it's just called application).
A standard Cocoa application bundle is actually a folder covered as a bundle
and contains a folder Contents which contains several items like the binary file and required resources.

An icon is located normally in the Resources folder.

in AppleScript you can refer to the bundle (or even to a plain script) with

Applescript:

path to me

The (HFS) path to the Resources folder is

Applescript:

(path to me as text) & "Contents:Resources:"

If your icon is in the Resources folder the path is

Applescript:

(path to me as text) & "Contents:Resources:Scheduling_icon.icns"


regards

Stefan

Offline

 

#4 2012-04-07 02:56:49 pm

vrttsllvn
Member
Registered: 2012-01-26
Posts: 6

Re: Error opening script as application

OK, this is where my inexperience becomes evident. So if I have it written this way:

Applescript:

on run
   display dialog "Welcome to DHAT." with title "DHAT" with icon file "Macintosh HD:Users:Everett:Desktop:Scheduling:DHAT:DHAT_icon.icns" buttons {"Cancel", "Calculate Daily Hour Allotment"} default button 2

and I want that icon to represent my script once it's packaged as an application, what do I need to amend?

Offline

 

#5 2012-04-07 03:03:02 pm

vrttsllvn
Member
Registered: 2012-01-26
Posts: 6

Re: Error opening script as application

Nevermind I got it. Thanks for your help.

Offline

 

#6 2012-04-07 03:03:18 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10490
Website

Re: Error opening script as application

put the icon in Contents:Resources of your bundle and use this

Applescript:


on run
   set iconFile to alias ((path to me as text) & "Contents:Resources:Scheduling_icon.icns")
   display dialog "Welcome to DHAT." with title "DHAT" with icon iconFile buttons {"Cancel", "Calculate Daily Hour Allotment"} default button 2
end run

if you want to share your script/app absolute paths are useless anyway


regards

Stefan

Offline

 

#7 2012-04-08 03:10:35 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3506

Re: Error opening script as application

Hi.

There's also a 'path to resource' command, which I presume still exists in Lion. This works with the icon in the applet's Resources folder:

Applescript:


on run
   set iconFile to (path to resource "Scheduling_icon.icns")
   display dialog "Welcome to DHAT." with title "DHAT" with icon iconFile buttons {"Cancel", "Calculate Daily Hour Allotment"} default button 2
end run


NG

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.036 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)