Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 04-10-2012, 04:28 PM   #1
Going Postal
Prospect
 
Join Date: Feb 2006
Posts: 14
Script with two options

Hello, ive put together a script that searches textwrangler for an entry and searches the network disk for a template. I would like to make it now so when i start the script it will ask what i would like to do giving me 3 buttons: Search Job Numbers, Search Templates, and cancel. when i select the Search job numbers button i want the textwrangler script to come up. When its finished searching for the value i would like it to go back to the beginning with the 3 buttons. I would like the same thing to happen when I do the Search Templates button, but after i select the file that it has done the search for.

Here is the Textwrangler script:

tell application "TextWrangler"
activate

set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
end tell


Here is the template search script:

set theFolder to {alias "Tin:Job Templates"}
set theFolderPP to POSIX path of theFolder


set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""


if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP


set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
set findResults to do shell script findCmd

set theMatches to paragraphs of findResults
set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
set chosenFiles to {}
repeat with f in chosenPaths
try
set end of chosenFiles to alias POSIX file (contents of f)
end try
end repeat
if length of chosenFiles is greater than 0 then
tell application "Finder"
activate
open chosenFiles
-- reveal chosenFiles
end tell


end if


Any help would be greatly appreciated!
Going Postal is offline   Reply With Quote
Old 04-10-2012, 04:48 PM   #2
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,784
I can't test your scripts, so I'm assuming they work. To get them as part of a dialog which prompts the user to choose an action, the script could look something like this:

Code:
tell application "System Events" to set frontProcess to name of the first process whose frontmost is true

set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)

if theChoice = "Search Job Numbers" then
	tell application "TextWrangler"
		activate
		
		set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
		find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
	end tell
	
	
else if theChoice = "Search Templates" then
	
	set theFolder to {alias "Tin:Job Templates"}
	set theFolderPP to POSIX path of theFolder
	
	
	set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
	
	
	if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
	
	
	set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
	set findResults to do shell script findCmd
	
	set theMatches to paragraphs of findResults
	set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
	if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
		set chosenFiles to {}
		repeat with f in chosenPaths
			try
				set end of chosenFiles to alias POSIX file (contents of f)
			end try
		end repeat
		if length of chosenFiles is greater than 0 then 
			tell application "Finder"
				activate
				open chosenFiles
				-- reveal chosenFiles
			end tell
		
		
	else
		activate frontProcess
		
	end if
end if
NaOH is offline   Reply With Quote
Old 04-10-2012, 04:57 PM   #3
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,784
I didn't properly read your post, so I missed how you wanted the dialog to reappear after running whatever option was selected the first time the dialog appeared. I think this properly corrects for that.

Code:
tell application "System Events" to set frontProcess to name of the first process whose frontmost is true

set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)

if theChoice = "Search Job Numbers" then
	tell application "TextWrangler"
		activate
		
		set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
		find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
	end tell
	
	run theChoice
	
else if theChoice = "Search Templates" then
	
	set theFolder to {alias "Tin:Job Templates"}
	set theFolderPP to POSIX path of theFolder
	
	
	set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
	
	
	if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
	
	
	set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
	set findResults to do shell script findCmd
	
	set theMatches to paragraphs of findResults
	set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
	if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
		set chosenFiles to {}
		repeat with f in chosenPaths
			try
				set end of chosenFiles to alias POSIX file (contents of f)
			end try
		end repeat
		if length of chosenFiles is greater than 0 then 
			tell application "Finder"
				activate
				open chosenFiles
				-- reveal chosenFiles
			end tell
		
		run theChoice
		
	else
		activate frontProcess
		
	end if
end if
NaOH is offline   Reply With Quote
Old 04-10-2012, 05:24 PM   #4
Going Postal
Prospect
 
Join Date: Feb 2006
Posts: 14
Thank you for that, i am just having one problem.

When i run the Search Job Numbers after it is finished it comes up with the error - "Search Job Numbers" doesn’t understand the run message.

and will not continue. It highlights "run theChoice" as the problem. It does the same when Search Templates is selected.

Thanks for your help
Going Postal is offline   Reply With Quote
Old 04-10-2012, 05:27 PM   #5
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,784
The problem is probably a combination of my mediocre scripting skills and the fact that I can't run your scripts for testing. Try this revision.

Code:
tell application "System Events" to set frontProcess to name of the first process whose frontmost is true

set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)

if theChoice = "Search Job Numbers" then
	tell application "TextWrangler"
		activate
		
		set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
		find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
	end tell
	
	tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
	
	set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
	
	if theChoice = "Search Job Numbers" then
		tell application "TextWrangler"
			activate
			
			set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
			find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
		end tell
		
		run theChoice
		
	else if theChoice = "Search Templates" then
		
		set theFolder to {alias "Tin:Job Templates"}
		set theFolderPP to POSIX path of theFolder
		
		
		set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
		
		
		if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
		
		
		set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
		set findResults to do shell script findCmd
		
		set theMatches to paragraphs of findResults
		set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
		if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
			set chosenFiles to {}
			repeat with f in chosenPaths
				try
					set end of chosenFiles to alias POSIX file (contents of f)
				end try
			end repeat
			if length of chosenFiles is greater than 0 then 
				tell application "Finder"
					activate
					open chosenFiles
					-- reveal chosenFiles
				end tell
			
			run theChoice
			
		else
			activate frontProcess
			
		end if
	end if
	
	
else if theChoice = "Search Templates" then
	
	set theFolder to {alias "Tin:Job Templates"}
	set theFolderPP to POSIX path of theFolder
	
	
	set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
	
	
	if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
	
	
	set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
	set findResults to do shell script findCmd
	
	set theMatches to paragraphs of findResults
	set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
	if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
		set chosenFiles to {}
		repeat with f in chosenPaths
			try
				set end of chosenFiles to alias POSIX file (contents of f)
			end try
		end repeat
		if length of chosenFiles is greater than 0 then 
			tell application "Finder"
				activate
				open chosenFiles
				-- reveal chosenFiles
			end tell
		
		tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
		
		set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
		
		if theChoice = "Search Job Numbers" then
			tell application "TextWrangler"
				activate
				
				set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
				find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
			end tell
			
			run theChoice
			
		else if theChoice = "Search Templates" then
			
			set theFolder to {alias "Tin:Job Templates"}
			set theFolderPP to POSIX path of theFolder
			
			
			set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
			
			
			if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
			
			
			set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
			set findResults to do shell script findCmd
			
			set theMatches to paragraphs of findResults
			set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
			if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
				set chosenFiles to {}
				repeat with f in chosenPaths
					try
						set end of chosenFiles to alias POSIX file (contents of f)
					end try
				end repeat
				if length of chosenFiles is greater than 0 then 
					tell application "Finder"
						activate
						open chosenFiles
						-- reveal chosenFiles
					end tell
				
				run theChoice
				
			else
				activate frontProcess
				
			end if
		end if
		
		
	else
		activate frontProcess
		
	end if
end if
NaOH is offline   Reply With Quote
Old 04-10-2012, 05:32 PM   #6
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,784
That last one is definitely not going to work.

Code:
tell application "System Events" to set frontProcess to name of the first process whose frontmost is true

set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)

if theChoice = "Search Job Numbers" then
	tell application "TextWrangler"
		activate
		
		set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
		find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
	end tell
	
	tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
	
	set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
	
	if theChoice = "Search Job Numbers" then
		tell application "TextWrangler"
			activate
			
			set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
			find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
		end tell
		
		
	else if theChoice = "Search Templates" then
		
		set theFolder to {alias "Tin:Job Templates"}
		set theFolderPP to POSIX path of theFolder
		
		
		set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
		
		
		if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
		
		
		set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
		set findResults to do shell script findCmd
		
		set theMatches to paragraphs of findResults
		set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
		if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
			set chosenFiles to {}
			repeat with f in chosenPaths
				try
					set end of chosenFiles to alias POSIX file (contents of f)
				end try
			end repeat
			if length of chosenFiles is greater than 0 then 
				tell application "Finder"
					activate
					open chosenFiles
					-- reveal chosenFiles
				end tell
			
			
		else
			activate frontProcess
			
		end if
	end if
	
	
else if theChoice = "Search Templates" then
	
	set theFolder to {alias "Tin:Job Templates"}
	set theFolderPP to POSIX path of theFolder
	
	
	set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
	
	
	if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
	
	
	set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
	set findResults to do shell script findCmd
	
	set theMatches to paragraphs of findResults
	set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
	if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
		set chosenFiles to {}
		repeat with f in chosenPaths
			try
				set end of chosenFiles to alias POSIX file (contents of f)
			end try
		end repeat
		if length of chosenFiles is greater than 0 then 
			tell application "Finder"
				activate
				open chosenFiles
				-- reveal chosenFiles
			end tell
		
		tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
		
		set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
		
		if theChoice = "Search Job Numbers" then
			tell application "TextWrangler"
				activate
				
				set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
				find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
			end tell
			
			
		else if theChoice = "Search Templates" then
			
			set theFolder to {alias "Tin:Job Templates"}
			set theFolderPP to POSIX path of theFolder
			
			
			set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
			
			
			if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
			
			
			set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
			set findResults to do shell script findCmd
			
			set theMatches to paragraphs of findResults
			set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
			if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
				set chosenFiles to {}
				repeat with f in chosenPaths
					try
						set end of chosenFiles to alias POSIX file (contents of f)
					end try
				end repeat
				if length of chosenFiles is greater than 0 then 
					tell application "Finder"
						activate
						open chosenFiles
						-- reveal chosenFiles
					end tell
				
				
			else
				activate frontProcess
				
			end if
		end if
		
		
	else
		activate frontProcess
		
	end if
end if
NaOH is offline   Reply With Quote
Old 04-10-2012, 06:04 PM   #7
Going Postal
Prospect
 
Join Date: Feb 2006
Posts: 14
That fixed the problem of the error, but now it will only do 2 searches then it shuts down, any ideas?
Its slowly getting there, thanks again for all your help
Going Postal is offline   Reply With Quote
Old 04-10-2012, 06:14 PM   #8
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,784
I didn't realize you wanted another repetition. Try this:

Code:
tell application "System Events" to set frontProcess to name of the first process whose frontmost is true

set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)

if theChoice = "Search Job Numbers" then
	tell application "TextWrangler"
		activate
		
		set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
		find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
	end tell
	
	tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
	
	set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
	
	if theChoice = "Search Job Numbers" then
		tell application "TextWrangler"
			activate
			
			set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
			find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
		end tell
		
		
	else if theChoice = "Search Templates" then
		
		set theFolder to {alias "Tin:Job Templates"}
		set theFolderPP to POSIX path of theFolder
		
		
		set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
		
		
		if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
		
		
		set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
		set findResults to do shell script findCmd
		
		set theMatches to paragraphs of findResults
		set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
		if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
			set chosenFiles to {}
			repeat with f in chosenPaths
				try
					set end of chosenFiles to alias POSIX file (contents of f)
				end try
			end repeat
			if length of chosenFiles is greater than 0 then 
				tell application "Finder"
					activate
					open chosenFiles
					-- reveal chosenFiles
				end tell
			
			
		else
			activate frontProcess
			
		end if
	end if
	
	
else if theChoice = "Search Templates" then
	
	set theFolder to {alias "Tin:Job Templates"}
	set theFolderPP to POSIX path of theFolder
	
	
	set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
	
	
	if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
	
	
	set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
	set findResults to do shell script findCmd
	
	set theMatches to paragraphs of findResults
	set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
	if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
		set chosenFiles to {}
		repeat with f in chosenPaths
			try
				set end of chosenFiles to alias POSIX file (contents of f)
			end try
		end repeat
		if length of chosenFiles is greater than 0 then 
			tell application "Finder"
				activate
				open chosenFiles
				-- reveal chosenFiles
			end tell
		
		tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
		
		set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
		
		if theChoice = "Search Job Numbers" then
			tell application "TextWrangler"
				activate
				
				set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
				find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
			end tell
			
			
		else if theChoice = "Search Templates" then
			
			set theFolder to {alias "Tin:Job Templates"}
			set theFolderPP to POSIX path of theFolder
			
			
			set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
			
			
			if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
			
			
			set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
			set findResults to do shell script findCmd
			
			set theMatches to paragraphs of findResults
			set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
			if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
				set chosenFiles to {}
				repeat with f in chosenPaths
					try
						set end of chosenFiles to alias POSIX file (contents of f)
					end try
				end repeat
				if length of chosenFiles is greater than 0 then 
					tell application "Finder"
						activate
						open chosenFiles
						-- reveal chosenFiles
					end tell
				
				
			else
				activate frontProcess
				
			end if
		end if
		
		tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
		
		set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
		
		if theChoice = "Search Job Numbers" then
			tell application "TextWrangler"
				activate
				
				set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
				find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
			end tell
			
			tell application "System Events" to set frontProcess to name of the first process whose frontmost is true
			
			set theChoice to button returned of (display dialog "Select a search:" buttons {"Cancel", "Search Templates", "Search Job Numbers"} default button 3)
			
			if theChoice = "Search Job Numbers" then
				tell application "TextWrangler"
					activate
					
					set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
					find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
				end tell
				
				
			else if theChoice = "Search Templates" then
				
				set theFolder to {alias "Tin:Job Templates"}
				set theFolderPP to POSIX path of theFolder
				
				
				set {text returned:theFilenamePattern} to display dialog "Enter a template to search for (Put * after template number to list all):" with title "Template Search " & theFolderPP default answer ""
				
				
				if length of theFolderPP is greater than 1 and theFolderPP ends with "/" then set theFolderPP to text 1 through -2 of theFolderPP
				
				
				set findCmd to "find " & quoted form of theFolderPP & " -iname " & quoted form of theFilenamePattern & " -print;true"
				set findResults to do shell script findCmd
				
				set theMatches to paragraphs of findResults
				set chosenPaths to choose from list theMatches with prompt "Matching Items: " & length of theMatches with empty selection allowed and multiple selections allowed
				if chosenPaths is not equal to false and length of chosenPaths is greater than 0 then
					set chosenFiles to {}
					repeat with f in chosenPaths
						try
							set end of chosenFiles to alias POSIX file (contents of f)
						end try
					end repeat
					if length of chosenFiles is greater than 0 then 
						tell application "Finder"
							activate
							open chosenFiles
							-- reveal chosenFiles
						end tell
					
					
				else
					activate frontProcess
					
				end if
			end if
			
		else
			activate frontProcess
			
			
		end if
	end if
	
else
	activate frontProcess
	
	
end if
In an ideal world, one of the folks around here who is better with AppleScript than I am will show up and make this a more efficient script, likely using a loop command.
NaOH is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:01 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.