0

someone please explain why this won't work. The script alone without the "if mainReturned = "File" then" works just fine but when I add it to another part of a script, things get weird. It highlights the word "on" on the 5th to last line of the script and then stops working etc. Please explain how I can fix it to add it to another script? The gist of the other script is basically if you enter a word the script will bring certain things up such as if I were to enter the work "File" it performs this. But it won't work. Its the format of if mainReturned = "File" then

            set SearchDir to choose folder
            set SearchTerm to text returned of ¬
(display dialog "Enter your search term below:" default answer "" with icon file "Macintosh HD:Users:<insert user's name.:Documents:robot-icon.png")
            set theResults to SpotlightSearch(SearchTerm, SearchDir)
            if theResults is not {""} then
                set theChoice to choose from list theResults with prompt ¬
                    "Here are the files that match the search term \"" & SearchTerm & ¬
                    "\" in directory \"" & SearchDir & "\":" cancel button name ¬
                    "Quit" OK button name "Reveal in Finder"
                if theChoice is not false then
                    tell application "Finder"
                        activate
                        reveal (POSIX file theChoice) as alias
                    end tell
                end if
            else
                display dialog "No Results Found." buttons ¬
                    {"Quit", "Search Again"} default button 2 with icon file "Macintosh HD:Users:<insert user's name>:Documents:robot-icon.png"
                if button returned of result is "Quit" then exit repeat
            end if
            on SpotlightSearch(SearchTerm, SearchDir)
                set theResults to paragraphs of ¬
                    (do shell script "mdfind " & quoted form of SearchTerm & ¬
                        " -onlyin " & quoted form of POSIX path of SearchDir)
            end SpotlightSearch
  • It’s better to fix an initial question that gets closed rather than delete the one on hold and ask again. apple.stackexchange.com/questions/351158/… - nice work editing this into shape - that helps immensely. – bmike Feb 11 at 23:31
  • Also, one thing that really helps when you are asking about programming / scripting / automation is to present a MCVE - stackoverflow.com/help/mcve - Minimal, Complete, Verifiable Example. In your case, a clear explanation that would let someone try and reproduce your error would get some upvotes and answers I believe,. – bmike Feb 11 at 23:33
  • sadly I don't know how I can rewrite it so its smaller, so this is all I got. My question is can anyone fix this so it's compatible with the format of code in AppleScript that goes if mainReturned = "" then <insert code above> – Londres Feb 12 at 0:58
  • That’s fine. Worst case, no one can help and you eventually post the answer. Thanks again for tidying up the questions, good improvements with the edits. – bmike Feb 12 at 1:02
  • just asking but with your experience, do you know how to fix my program or no...? it would be most appreciated – Londres Feb 12 at 1:50

You must log in to answer this question.

Browse other questions tagged .