I have a script. When I search for something (I searched for the word “pie”) my computer “freaks out” and the speakers go crazy with a noise that is very painful to my ears. When I close the script – everything goes back to normal. Here it is, search for something and prepare to mute your mac:
set thespotlightquery to text returned of (display dialog "What do you want to search?" default answer "" buttons {"Search!"} default button 1)
set spotlightquery to quoted form of thespotlightquery
set thefolders to {(path to applications folder as string), (path to home folder as string) & "Documents", (path to home folder as string) & "Downloads", (path to home folder as string) & "Desktop", (path to home folder as string) & "Movies", (path to home folder as string) & "Pictures", (path to home folder as string) & "Music"}
set founditems to {}
repeat with i in thefolders
set thepath to quoted form of POSIX path of (i as string)
if exists thepath then
set command to "mdfind -onlyin " & thepath & " " & spotlightquery
set founditems to founditems & (paragraphs of (do shell script command))
end if
end repeat
set numb to 1
set endfalse to false
if founditems is {} or founditems is {""} then
display dialog "No search results!" buttons {"OK"} default button 1 with title "Your search for \"" & thespotlightquery & "\""
else
repeat
set i to item numb of founditems as string
tell application "Finder" to set huh to exists (POSIX file i)
if huh then
set thesize to size of (get info for (POSIX file i))
set thekind to kind of (get info for (POSIX file i))
set thename to displayed name of (get info for (POSIX file i))
set creation to creation date of (get info for (POSIX file i))
set visibility to visible of (get info for (POSIX file i))
set dialog to "Name: \"" & thename & "\"" & return & return & "Kind: " & thekind & return & return & "Size: " & thesize & " bytes" & return & return & "Creation Date: " & (creation as string) & return & return & "Visibility: " & (visibility as string) & return & return & "Path: " & i & return
set button to (choose from list {"Open", "Show", "Peak at contents", "Back", "Next", "End"} with prompt dialog with title "Your search for \"" & spotlightquery & "\"") as string
else
set button to "Next"
end if
if button is "Open" then
try
set theapp to default application of (get info for (POSIX file i)) as string
tell application theapp to open (POSIX file i as string)
activate application theapp
on error e
display dialog "An error has occured trying to open your file:" & return & return & e buttons {"OK"} default button 1
end try
exit repeat
else if button is "Back" then
if numb is not 1 then
set numb to numb - 1
else
beep
end if
else if button is "Next" then
if numb is not (count founditems) then
set numb to numb + 1
else
beep
end if
else if button is "End" then
exit repeat
else if button is "Show" then
tell application "Finder"
try
select (POSIX file i as alias)
activate
on error e
display dialog "An error has occured" & return & "trying to show you the file:" & return & return & return & e
end try
end tell
else if button is "Peak at contents" then
if name extension of (info for (POSIX file i as alias)) is in {"html", "strings", "txt", "m", "h", "applescript"} then
set read_ to read (POSIX file i as alias) as string
if (count read_) < 1300 then
display dialog "Your file contents are as follows:" & return & return & read_ buttons {"OK"} default button 1
else
choose from list paragraphs of read_ OK button name "Finish" cancel button name "Finish" with prompt "Your file contents are as follows:"
end if
else
display dialog "This file format is not currently supported with the read function of this application." buttons {"OK"} default button 1
end if
else if button is "false" then
if endfalse is true then exit repeat
set endfalse to true
beep
end if
end repeat
end if