Relative Path - Simple

Hi all,

We are just putting the finishing touches to a script but have stumbled across something that should be easy to fix but we can’t see the obvious way.

This script we know works and mounts the dmg as it should but unfortunately cannot be used as we intend to run this script on numerous different computers all with different usernames.

say "Begin install"
tell application "Finder"
	if not (exists "Adobe Photoshop CS5 Extended") then
		do shell script "hdiutil attach '/Users/TS/Desktop/Packages/Software/Adobe Photoshop CS5 Extended/installer/Adobe Photoshop CS5 Extended.dmg'"
	end if
end tell

This script we are trying to mount the dmg from the relative path as this is how it will be when pulled down from the server.

say "Begin install"
tell application "Finder"
	if not (exists "Adobe Photoshop CS5 Extended") then
		do shell script "hdiutil attach '../installer/Adobe Photoshop CS5 Extended.dmg'"
	end if
end tell

The dmg will be located on /user/Desktop/Packages/Software/application/installer once pulled down onto each Mac.
The AppleScript application will be located /user/Desktop/Packages/Software/application/script once pulled down also.

Any help appreciated.

Cheers

Will

Going to desktop folder can be done many different ways

as hfs+ path

path to desktop folder 

simple posix path to desktop

set posixPathToDesktop to "~/Desktop"

Gettimng the real path to desktop (some command line utiliies can only work with absolute paths)


set posixPathToDesktop to do shell script "cd ~/Desktop;pwd"

For your solution I’ll go for the last option. Your code would look like


set PosixPathToInstaller to (do shell script "cd ~/Desktop;pwd" )& "/Packages/Software/Adobe Photoshop CS5 Extended/installer/Adobe Photoshop CS5 Extended.dmg" as string

Your test condition will also need to be more meaningful than asking the Finder if a certain string exists!

Thanks for your help.

Slightly confused how this incorporates the hdiutil with your bottom example.

Thanks

Will

Something like this will work to mount the image

set PosixPathToInstaller to (do shell script "cd ~/Desktop;pwd") & "/Packages/Software/Adobe Photoshop CS5 Extended/installer/Adobe Photoshop CS5 Extended.dmg" as string

if not fileExists("/Volumes/Adobe Photoshop CS5 Extended") then
	--only mount if disk image is not already mounted
	do shell script "hdiutil attach " & quoted form of PosixPathToInstaller
end if

on fileExists(posixPath)
	return not (do shell script "test -e " & quoted form of posixPath & "; echo $?") as integer as boolean
end fileExists

Thank you very much. That worked perfectly.