problem: obtaining the path of a folder/ finding a folder..

Hi I am writing a script for the Myth II gaming community to allow them to easily switch which server they are using. This involves moving some files around from a base folder: Myth II, to a holder folder called Plugins. When the marius.net server is enabled the marius plugins will be in the plugins folder and the playmyth plugins will be in the base Myth II folder.

Currently my Myth II folder in in my Hard Disk folder (startup disk) which means the script would only currently work if the users Myth II folder was in the same place.

I need a way of locating the myth 2 folder. But that leaves me with another problem, the paths specified in my code would then be wrong. I think I would have to use variables to pass the path into the code.

Here is my current code: It asks which server you want to activate and then sets up the files as per which server you selected. If you select the server which is already activated is tells you.

Note: It also removes a file called bungie.net from a preferences folder each time a server is switched.


display dialog "Enable Which Server?" buttons {"Marius", "PlayMyth"}

if button returned of result = "Marius" then
	
	tell application "Finder"
		if (the file "marius net Patch" of folder "Myth II ƒ" of startup disk exists) then
			
			
			activate
			select startup disk
			open selection
			select folder "Myth II ƒ" of startup disk
			open selection
			select file "marius net Patch" of folder "Myth II ƒ" of startup disk
			move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
			select file "marius net DNS" of folder "Myth II ƒ" of startup disk
			move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
			select folder "preferences" of folder "Myth II ƒ" of startup disk
			open selection
			select file "bungienet" of folder "preferences" of folder "Myth II ƒ" of startup disk
			delete selection
			close container window of folder "preferences" of folder "Myth II ƒ" of startup disk
			select folder "plugins" of folder "Myth II ƒ" of startup disk
			open selection
			select file "PlayMyth v1.2" of folder "plugins" of folder "Myth II ƒ" of startup disk
			move selection to folder "Myth II ƒ" of startup disk
			select file "PMI_Classic" of folder "plugins" of folder "Myth II ƒ" of startup disk
			move selection to folder "Myth II ƒ" of startup disk
			select file "Patch 1.2" of folder "plugins" of folder "Myth II ƒ" of startup disk
			move selection to folder "Myth II ƒ" of startup disk
			close container window of folder "plugins" of folder "Myth II ƒ" of startup disk
			close container window of folder "Myth II ƒ" of startup disk
			close container window of startup disk
		else
			display dialog "Marius Already Installed"
			
		end if
		
	end tell
	
	
	
	
	
	
else
	
	if button returned of result = "PlayMyth" then
		tell application "Finder"
			
			if (the file "PlayMyth v1.2" of folder "Myth II ƒ" of startup disk exists) then
				activate
				select startup disk
				open selection
				select folder "Myth II ƒ" of startup disk
				open selection
				select file "Patch 1.2" of folder "Myth II ƒ" of startup disk
				move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
				select file "PlayMyth v1.2" of folder "Myth II ƒ" of startup disk
				move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
				select file "PMI_Classic" of folder "Myth II ƒ" of startup disk
				move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
				select folder "plugins" of folder "Myth II ƒ" of startup disk
				open selection
				select file "marius net Patch" of folder "plugins" of folder "Myth II ƒ" of startup disk
				move selection to folder "Myth II ƒ" of startup disk
				select file "marius net DNS" of folder "plugins" of folder "Myth II ƒ" of startup disk
				move selection to folder "Myth II ƒ" of startup disk
				close container window of folder "plugins" of folder "Myth II ƒ" of startup disk
				select folder "preferences" of folder "Myth II ƒ" of startup disk
				open selection
				select file "bungienet" of folder "preferences" of folder "Myth II ƒ" of startup disk
				delete selection
				
				activate
				select file "PlayMyth v1.2" of folder "Myth II ƒ" of startup disk
				move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
				select file "Patch 1.2" of folder "Myth II ƒ" of startup disk
				move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
				select file "PMI_Classic" of folder "Myth II ƒ" of startup disk
				move selection to folder "plugins" of folder "Myth II ƒ" of startup disk
				
				activate
				close container window of folder "Myth II ƒ" of startup disk
				close container window of folder "preferences" of folder "Myth II ƒ" of startup disk
				close container window of startup disk
				
			else
				display dialog "PlayMyth Already Installed"
			end if
		end tell
		
		
	end if
	
end if

WHen i need such a thinf what I do is the following :
1 - declare a property of type boolean set it to false
2 - the first time you run the script, the boolean is false, ask the user to locat its myth folder (using a choose folder)
3 - store this path in a property so you don’t ahve to ask the user every time. (let set the property name is myMythPath)
4 - set the boolean to true

now you have the path to your folder

all you path will be of type :

select folder “ThisFOlder” of folder myMythPath

PS : when you run the script you should verify wether or not the folder exist, if not then the user has changed the location of the folder, so ask him again to locate it.

I’ve been doing the same thing but a diffrent way. I’m trying to do where the script is put in the Myth folder and the script then works from there. But it doesn’t seem to be working.


display dialog "Remove which server?" buttons {"PlayMyth", "Marius"}
if button returned of result = "PlayMyth" then
	try
		tell application "Finder"
			activate
			select "plugins:PlayMyth v1.2"
			select (every file whose name starts with "PMI")
			try
				if folder "PlayMyth Plugs" exists then
					move selections to folder "PlayMyth Plugs" of folder "plugins"
				else
					make folder "PlayMyth Plugs"
					move selections to folder "PlayMyth Plugs" of folder "plugins"
				end if
			end try
		end tell
	end try
end if

if button returned of result = "Marius" then
	try
		tell application "Finder"
			activate
			select "marius net Patch"
			move selection to folder "removed" of folder "plugins"
			try
				if folder "MariusNet Plugs" exists then
					move selections to folder "MariusNetPlugs" of folder "plugins"
				else
					make folder "MariusNet Plugs"
					move selection to folder "MariusNet Plugs" of folder "plugins"
				end if
			end try
		end tell
	end try
end if

I think the “choose folder” creates an alias. How do I get the path from this alias?

set chosenFol to (choose folder) as text

Here is a litle routine I wrote , it might help you to achieve your work


property firstRun : true
property MythFolderPath : ""

on run
	checkFirstRun()
	--here you do your stuff
end run

on checkFirstRun()
	if firstRun = true then
		set MythFolderPath to choose folder
		if MythFolderPath = false then
			quit
		else
			set firstRun to true
		end if
	end if
end checkFirstRun

on quit
	continue quit
end quit

ok it works great until it gets to my part of the script which doesn’t work correctly. i get this error:
“The variable result is not defined”
here:
if button returned of result = “Marius” then

it then hghlight “Marius”

and heres the code:


property firstRun : true
property MythFolderPath : ""

on run
	checkFirstRun()
	--here you do your stuff 
	display dialog "Remove which server?" buttons {"PlayMyth", "Marius"}
	if button returned of result = "PlayMyth" then
		try
			tell application "Finder"
				activate
				select "plugins:PlayMyth v1.2"
				select (every file whose name starts with "PMI")
				try
					if folder "PlayMyth Plugs" exists then
						move selections to folder "PlayMyth Plugs" of folder "plugins"
					else
						make folder "PlayMyth Plugs"
						move selections to folder "PlayMyth Plugs" of folder "plugins"
					end if
				end try
			end tell
		end try
	end if
	
	if button returned of result = "Marius" then
		try
			tell application "Finder"
				activate
				select "marius net Patch"
				try
					if folder "MariusNet Plugs" exists then
						move selection to folder "MariusNetPlugs" of folder "plugins"
					else
						make folder "MariusNet Plugs"
						move selection to folder "MariusNet Plugs" of folder "plugins"
					end if
				end try
			end tell
		end try
	end if
end run

on checkFirstRun()
	if firstRun = true then
		set MythFolderPath to choose folder
		if MythFolderPath = false then
			quit
		else
			set firstRun to true
		end if
	end if
end checkFirstRun

on quit
	continue quit
end quit

Wow, working well now, thanks jean baptiste and admin dude :slight_smile:

my pleasure

whats wrong with my script? :?

I think you need to use a variable to capture the result of your dialog since ‘result’ changes throughout the script. Instead of:

display dialog "Remove which server?" buttons {"PlayMyth", "Marius"}

Try:

 set dialog1 to display dialog "Remove which server?" buttons {"PlayMyth", "Marius"}

You’ll then need to change the script to use the ‘dialog1’ instead of ‘result’.

well it no longer gives an error. and neither does it do anything else. The script should work, but nothing happens. I runs through the script (i think) with no error. Oh well, Atleast CoV got his working perfectly, so alls good :shock: