I’m new to this forum. Also, I’m not very experienced at AppleScript, however I have managed to write a few really simplistic applescripts in times past.
I’ve been searching for an answer to this for about a month. I’ve searched this site and others without finding much help.
I’m working with a non-profit org as a volunteer. As it turns out, I am the only experienced Mac user in the whole place. They’ve tagged me as the person to get this done. They have no money, so it’s up to me to code this.
I’ve managed to code an installer. It places one folder at the root of the boot volume and two text files in the user’s home folder. Somehow I was able to get this installer made but it only works in Leopard/SL, but not in Tiger, the target OS. I saved this as a application bundle with the installation files in the bundle - in the Resources folder.
My first attempt at this installer worked in Tiger, but had no conditionals and the installer and the files were separate and on a dmg - it was just good enough to send out to beta test.
Here’s the code from my installer that works in Leopard but not in Tiger (Note: I have shortened the dialog messages):
get path to resource "options" in directory "installation" (*I tried changing this to (path to me as string) & "Contents:Resources:installation:" for use in Tiger, but it was a no go*)
set TheFiles to path to resource "installation"
tell application "Finder"
set _files1 to the folder "options" of TheFiles
--Make user aware of what is going to happen and get confirmation
display dialog "Click Stop or Install." with icon caution buttons {"Stop", "Install"} default button 2
if the button returned of the result is "Stop" then
tell current application to quit
--check if user has a previous version installed
else
if (exists folder "options" of the startup disk) then
display dialog "You have a previous version installed. Click Stop or Overwite" with icon note buttons {"Stop", "Overwrite"} default button 1
if button returned of result is "Overwrite" then
--Get rid of the a previous version installation if user indicated so
try
delete folder "options" of the startup disk
end try
delay 1
copy _files1 to the startup disk
--Check if user has a custom xxxx file
if (exists file "xxxx" of home) then
display dialog "You have a custom xxxx file" with icon note buttons {"Cancel Installation", "Install Anyway"} default button 1
if button returned of result is "Cancel Installation" then
tell current application to quit
else
try
delete file "xxxx" of home
delete file "yyyy" of home
delay 1
end try
copy file "xxxx" of TheFiles to home
copy file "yyyy" of TheFiles to home
do shell script "<code>"
display dialog "The installation was successful" buttons {"Okay"} default button 1
if button returned of result is "Okay" then
tell current application to quit
end if
end if
else if button returned of result is "Stop" then
tell current application to quit
end if
end if
end if
end if
end tell
I would rather have the second conditional “if (exists folder “options” of the startup disk) then” as the first. But when I write it that way the script quits as soon as it launches.
In 10.4 it will only run if there is a previous installation present. If there is no previous installation my installer launches and then immediately quits.
MacBook Pro running Mac OS X 10.5.8, Mac OS X 10.6.2, Mac OS X 10.4.11 and Mac OS 9.0.4 emulated
iBook G4 12" running Mac OS X 10.4.11 and Classic
the command copy doesn’t copy files. It assignes a value to a variable.
The proper Finder command is duplicate
try this
set TheFiles to ((path to me as string) & "Contents:Resources:installation:") as alias
tell application "Finder"
set _files1 to the folder "options" of TheFiles
--Make user aware of what is going to happen and get confirmation
display dialog "Click Stop or Install." with icon caution buttons {"Stop", "Install"} default button 2
if the button returned of the result is "Stop" then
quit
--check if user has a previous version installed
else
if (exists folder "options" of the startup disk) then
display dialog "You have a previous version installed. Click Stop or Overwite" with icon note buttons {"Stop", "Overwrite"} default button 1
if button returned of result is "Overwrite" then
--Get rid of the a previous version installation if user indicated so
try
delete folder "options" of the startup disk
end try
delay 1
duplicate _files1 to the startup disk
--Check if user has a custom xxxx file
if (exists file "xxxx" of home) then
display dialog "You have a custom xxxx file" with icon note buttons {"Cancel Installation", "Install Anyway"} default button 1
if button returned of result is "Cancel Installation" then
quit
else
try
delete file "xxxx" of home
delete file "yyyy" of home
delay 1
end try
duplicate file "xxxx" of TheFiles to home
duplicate file "yyyy" of TheFiles to home
do shell script "<code>"
display dialog "The installation was successful" buttons {"Okay"} default button 1
if button returned of result is "Okay" then
quit
end if
end if
else if button returned of result is "Stop" then
quit
end if
end if
end if
end if
end tell
Note: It’s bad programming habit to put custom files on the top level of the startup disk or directly into the home folder. There is an folder Application Support in both /Library and ~/Library for this purpose.
Okay, thanks for the correction. I’ll work on it tonight and see how it goes.
StefanK also said:
Thank-you very much for the advice. I know you are right and I regret having to do it that way. But, I have very little education to call upon and have not yet figured out how else to do this.
This is a Mac OS 10.4 work-around for a WINE port. The files that are in the home folder are resource files for X11 to use (X11 looks in home for resources) and the folder at the root level of the boot volume is a X window manager.
If I knew how to compile and build unix apps so they could be put into /Library/Application Support/ I would.
Those changes of duplicate replacing copy and adding the as alias to the path to me line allowed the script to get a little further. But, still no joy. The script still quits at the second conditional (line 11) if the folder ‘options’ does not exist. If the folder does exist the script deletes it and copies the new one to the HDD, which it is supposed to do, but then it quits without going any further.
If someone knows of an example or tutorial regarding multiple conditionals, could you point me in that direction please?
set TheFiles to ((path to me as string) & "Contents:Resources:installation:") as alias
tell application "Finder"
set _files1 to the folder "options" of TheFiles
--Make user aware of what is going to happen and get confirmation
display dialog "Click Stop or Install." with icon caution buttons {"Stop", "Install"} default button 2
if the button returned of the result is "Stop" then
quit
--check if user has a previous version installed
else
if (exists folder "options" of the startup disk) then
display dialog "You have a previous version installed. Click Stop or Overwite" with icon note buttons {"Stop", "Overwrite"} default button 1
if button returned of result is "Stop" then quit
--Get rid of the a previous version installation if user indicated so
try
delete folder "options" of the startup disk
end try
delay 1
end if
duplicate _files1 to the startup disk
--Check if user has a custom xxxx file
if (exists file "xxxx" of home) then
display dialog "You have a custom xxxx file" with icon note buttons {"Cancel Installation", "Install Anyway"} default button 1
if button returned of result is "Cancel Installation" then
quit
else
try
delete file "xxxx" of home
delete file "yyyy" of home
delay 1
end try
duplicate file "xxxx" of TheFiles to home
duplicate file "yyyy" of TheFiles to home
do shell script "<code>"
display dialog "The installation was successful" buttons {"Okay"} default button 1
if button returned of result is "Okay" then
quit
end if
end if
else if button returned of result is "Stop" then
quit
end if
end if
end tell
In this case it’s better to check the button “Stop” instead of overwrite
If the folder does not exist, the script continues to copy the files
I forgot to pointed out: using the term quit instead of tell current application to quit, causes the Finder to quit instead the script.
Thank-you for your help, StefanK. Unfortunately none of your suggestions in your last post gave any improvement. Still, I very much appreciate your help.
What diagnostics can I use to isolate the problem?
Yes. Script is saved as an application bundle.
All testing is done from the Finder, never from the script editor.
All files exist.
The file structure is as it should be.
I get zero error messages.
As stated before, but maybe I wasn’t clear enough:
If the files exist as in a previous installation my installer application bundle runs,
I click the Install button, it then deletes the old “options” folder and installs the new “options” folder, it then quits at that point, going no further in the program. It never gets to files xxxx or yyyy. Never gets to my “do shell script”. Never gets to “The installation was successful” dialog.
If there is no previous installation, my installer application bundle runs until I click the Install button and then quits right there. No errors are given.
I’ve tried commenting out different lines and moving my commands around, but nothing gets me any closer.
If I can’t get this by the time the org needs it, I’ll just have to use my original installer, it worked, but there were no conditionals.
Now I got it. The install routine was never be executed, if the xxxx file doesn’t exist.
Try this, actually the quit commands should work.
Although it’s not necessary, I added a quit handler
on run
set TheFiles to ((path to me as string) & "Contents:Resources:installation:") as alias
tell application "Finder"
set _files1 to the folder "options" of TheFiles
--Make user aware of what is going to happen and get confirmation
display dialog "Click Stop or Install." with icon caution buttons {"Stop", "Install"} default button 2
if the button returned of the result is "Stop" then
quit
--check if user has a previous version installed
else
if (exists folder "options" of the startup disk) then
display dialog "You have a previous version installed. Click Stop or Overwite" with icon note buttons {"Stop", "Overwrite"} default button 1
if button returned of result is "Stop" then quit
--Get rid of the a previous version installation if user indicated so
try
delete folder "options" of the startup disk
end try
delay 1
end if
duplicate _files1 to the startup disk
--Check if user has a custom xxxx file
if (exists file "xxxx" of home) then
display dialog "You have a custom xxxx file" with icon note buttons {"Cancel Installation", "Install Anyway"} default button 1
if button returned of result is "Cancel Installation" then quit
end if
try
delete file "xxxx" of home
delete file "yyyy" of home
delay 1
end try
duplicate file "xxxx" of TheFiles to home
duplicate file "yyyy" of TheFiles to home
do shell script "<code>"
display dialog "The installation was successful" buttons {"Okay"} default button 1
if button returned of result is "Okay" then
quit
end if
end if
end tell
end run
on quit
continue quit
end quit