|
|
#1 |
|
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! |
|
|
|
|
|
#2 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
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
|
|
|
|
|
|
#3 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
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
|
|
|
|
|
|
#4 |
|
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 |
|
|
|
|
|
#5 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
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
|
|
|
|
|
|
#6 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
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
|
|
|
|
|
|
#7 |
|
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 |
|
|
|
|
|
#8 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
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
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|