So I would like to tie what ever is passed in to the two fields as two separate variables and then when I click Search it would pass them to the shell command find $PATH -name ‘$FILENAME’ So in the case of my image it would search the Volume Share for files named picture.jpg. I’ve tried reading the manual for IB but don’t know where to start. Is this a binding? How do I assign it to a variable? How do I tie the find command to the Search button? As you can tell I’m definitely a newb, but I want to learn this stuff. So any help would be greatly appreciated.
Thank you for that link. It has gotten me 99% of the way there (I think). I am having an issue though, In my fields that are just text I don’t know what set them as? I tried set as string and I tried set as text and I get an error saying it can’t set them as string or Unicode text. Here is what I have so far:
on clicked theObject
tell window of theObject
set thePath to contents of text field "path" as text
set thePathPP to POSIX path of thePath
set theFilename to contents of text field "filename" as text
if length of thePathPP is greater than 1 and thePathPP ends with "/" then set thePathPP to text 1 through -2 of thePathPP
set findCmd to "find " & quoted form of thePathPP & " -iname " & "*" & quoted form of theFilename & "*" & " -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
reveal chosenFiles
end tell
end if
end tell
end clicked
on should quit after last window closed theObject
return true
end should quit after last window closed
I got most of that from chrys in this thread. It works great as just an Applescript, but I merged the two together (the tutorial and the applescript). So, what type do they need to be set as?
OK, now I have figured this out. I apparently forgot to set the Title of one of the fields. I set that and it works. Now, I have another issue though, it pops up another window with my results of the search like I want. However, when I click on one of those items, it should reveal the item in Finder but it’s not. What do I need to do differently to reveal the item in Finder?
There is no coercion needed at all. The content of an text field is always text.
Note: It’s strongly recommended to use referencing tell blocks only for the appropriate lines
on clicked theObject
tell window of theObject
set thePath to contents of text field "path"
set theFilename to contents of text field "filename"
end tell
set thePathPP to POSIX path of thePath
.
Sweet, I fixed the coercion so there was none, what you said makes perfect sense. I was still having the problem of Finder not revealing the item. Then I fixed the tell blocks like you said and now the reveal in Finder works perfectly. Thanks for your help.