Finding a (returned result) number in a range of values

Hi All,

I have been trying to no avail to write a script, which once I have input a number (for example 20) in a dialog box, checks if this number is in a range of numbers (eg 0 to 50, 50 to 100 etc.). Once this inputted number is found in a range it then does the same task as any other in that range. For example here is a script to open a folder within a folder structure of numbered ranges…

tell application "Finder"
	display dialog ¬
		"Please choose your desired Server:" with icon caution buttons {"HI RES", "LO RES"} default button "HI RES"
	set chooseserver to (button returned of result)
	if chooseserver is ("LO RES") then set thedisk to "Low_Res_servername"
	if chooseserver is ("HI RES") then set thedisk to "Hi_Res_servername"
	display dialog ¬
		"Please choose your desired picture type:" with icon caution buttons {"Holiday", "Family", "Misc"} default button "Misc"
	set choosetype to (button returned of result)
	if choosetype is ("Holiday") then set thefolder1 to "Holiday_Images"
	if choosetype is ("Holiday") then set pfix to "HI"
	if choosetype is ("Family") then set thefolder1 to "Family_Images"
	if choosetype is ("Family") then set pfix to "FI"
	if choosetype is ("Misc") then set thefolder1 to "Misc_Images"
	if choosetype is ("Misc") then set pfix to "MI" 
	display dialog ¬
		"INPUT REFERENCE NUMBER:" default answer "" buttons {"OK", "CANCEL"} default button "OK"
	set refno to (text returned of result)
	if refno is "1" then set thefolder2 to "Images0000_0999" --this is where I need help otherwise it'll be a huge list and alot of typing!! I hoped i could do something like if refno is ("0" to "999") then set thefolder2 to "Images0000_0999"
	if refno is "2" then set thefolder2 to "Images0000_0999"
	if refno is "1001" then set thefolder2 to "Images1000_1999" --etc etc....
	pfix & refno 
	set endpath to result --display dialog endpath
	open folder endpath in folder thefolder2 in folder thefolder1 in disk thedisk
end tell

Please excuse the rough script I’ve only recently started looking at the possibilities Applescript offers and this is my first attempt at scripting - but I can’t find any relevant help on what I need and its driving me mad.
My plans would then be to use xcode to build a front-end to create an always open app with radio buttons for hi/lo server, a list for image type (so I could add more genres) and search field.

Thanks in advance on any help (or suggestions of what I’m sure are simpler ways to what I’ve done)!

Tyler01

Hi, Tyler01.

This should give you the idea.

tell application "Finder"
	display dialog ¬
		"Please choose your desired Server:" with icon caution buttons {"HI RES", "LO RES"} default button "HI RES"
	set chooseserver to (button returned of result)
	if chooseserver is ("LO RES") then
		set thedisk to "Low_Res_servername"
	else
		set thedisk to "Hi_Res_servername"
	end if
	display dialog ¬
		"Please choose your desired picture type:" with icon caution buttons {"Holiday", "Family", "Misc"} default button "Misc"
	set choosetype to (button returned of result)
	if choosetype is ("Holiday") then
		set thefolder1 to "Holiday_Images"
		set pfix to "HI"
	else if choosetype is ("Family") then
		set thefolder1 to "Family_Images"
		set pfix to "FI"
	else
		set thefolder1 to "Misc_Images"
		set pfix to "MI"
	end if
	display dialog ¬
		"INPUT REFERENCE NUMBER:" default answer "" buttons {"OK", "CANCEL"} default button "OK"
	set refno to (text returned of result) as number
	if refno < 0 then
		display dialog "No negatives, idiot!"
	else if refno < 1000 then
		set thefolder2 to "Images0000_0999" --this is where I need help otherwise it'll be a huge list and alot of typing!! I hoped i could do something like if refno is ("0" to "999") then set thefolder2 to "Images0000_0999"
	else if refno < 2000 then
		set thefolder2 to "Images1000_1999"
	else if refno < 3000 then
		--etc etc....
	end if
	set endpath to pfix & refno
	
	open folder endpath in folder thefolder2 in folder thefolder1 in disk thedisk
end tell

The if-else-if logic above is that if a number isn’t less than, say, 1000, but then it’s shown to be less than 2000, it must be between 1000 and 1999. The remaining else-ifs in that block are then not performed.

Hello

It seems that Nigel Garvey script may be shorten a bit

tell application "Finder"
	display dialog ¬
		"Please choose your desired Server:" with icon caution buttons {"HI RES", "LO RES"} default button "HI RES"
	set chooseserver to (button returned of result)
	if chooseserver is ("LO RES") then
		set thedisk to "Low_Res_servername"
	else
		set thedisk to "Hi_Res_servername"
	end if
	display dialog ¬
		"Please choose your desired picture type:" with icon caution buttons {"Holiday", "Family", "Misc"} default button "Misc"
	set choosetype to (button returned of result)
	if choosetype is ("Holiday") then
		set {thefolder1, pfix} to {"Holiday_Images", "HI"}
	else if choosetype is ("Family") then
		set {thefolder1, pfix} to {"Family_Images", "FI"}
	else
		set {thefolder1, pfix} to {"Misc_Images", "MI"}
	end if
	display dialog ¬
		"INPUT REFERENCE NUMBER:" default answer "" buttons {"OK", "CANCEL"} default button "OK"
	set refno to (text returned of result) as number
	if refno < 0 then
		display dialog "No negatives, idiot!"
	else
		set thefolder2 to "Images" & (refno div 1000) & "000_" & (refno div 1000) & "999"
	end if
	set endpath to pfix & refno
	
	open folder endpath in folder thefolder2 in folder thefolder1 in disk thedisk
end tell

Yvan KOENIG (from FRANCE jeudi 19 octobre 2006 08:46:23)

Well spotted, Ivan. :slight_smile: The alternative ending I woke up with this morning was this (assuming a range from “0000” to “9999”):

tell application "Finder"
	
	-- Blah blah, then this ending:
	
	display dialog ¬
		"INPUT REFERENCE NUMBER:" default answer "" buttons {"OK", "CANCEL"} default button "OK"
	set refno to (text returned of result) as number
	if (refno < 0) or (refno > 9999) then
		display dialog "Number out of range (0000-9999)"
	else
		tell (100000999 + refno div 1000 * 10001000) as text
			set thefolder2 to "Images" & text 2 thru 5 & "_" & text 6 thru 9
		end tell
		set endpath to pfix & text 2 thru 5 of ((refno + 10000) as text)
		
		open folder endpath in folder thefolder2 in folder thefolder1 in disk thedisk
	end if
end tell

Thats great, thankyou to you both!! I’m finding Applescript quite addictive at the minute and this script has been on my mind for a few days. Trouble with that is I thought of a different approach - which is to get the folder information from the server/folder itself, dissasemble this list and use that. I thought of this before I saw this script, and I need a little time to digest your solutions! Which do you think is a better course of action?