Hello.
Has anyone got a clue where to start with the creation of a ‘Smart Folder’ ?
I need a series of 10 folders searching for spotlight comments eg. find-1, find-2 etc.
many thanks
LJ
Hello.
Has anyone got a clue where to start with the creation of a ‘Smart Folder’ ?
I need a series of 10 folders searching for spotlight comments eg. find-1, find-2 etc.
many thanks
LJ
I assume that you want to create 10 Saved Searches windows. Unfortunately, the Finder doesn’t reveal that in its dictionary, so you’ll have to GUI script them. The script below is the one I use; perhaps you can modify it to suit your purpose, except that each time you save, you’ll have to enter a name for the saved search.
tell application "Finder"
activate
set Places to {documents folder, scripts folder, pictures folder, movies folder, applications folder} -- change this to suit your needs.
-- Need their names for the choose from list statement.
set PN to {"1. Documents", "2. Scripts", "3. Pictures", "4. Movies", "5. Applications"}
-- Grab the first character of the folder chosen to use as an index into Places.
set choice to ((character 1 of item 1 of (choose from list PN)) as integer)
if choice < 5 then -- Applications is not in User Domain.
set tFolder to path to (item choice of Places) from user domain
set DefButton to "In Content" -- the normal search parameter
else -- the Applications folder was chosen.
set tFolder to path to (item choice of Places) from local domain
set DefButton to "In File Name" -- more meaningful for Applications, although finding by content will still find names. Not strictly necessary, in other words.
end if
set Fname to word -1 of item choice of PN -- just the name, not the number.
set {Btn, toFind} to {button returned, text returned} of (display dialog "Enter the word(s) to find in Fname" default answer "" buttons {"Cancel", "In Content", "In File Name"} default button DefButton with icon 1)
open tFolder -- the chosen folder.
delay 0.5 -- wait for the Finder to get on with it.
-- A bit of GUI Scripting (tested in Leopard)
tell application "System Events" to tell process "Finder"
(* We have the chosen folder window open. Its search box is the only text field in the toolbar of the open window, and the toolbar only has one group to which the search box belongs. The box itself contains a value, so the following line sets that to our search term *)
set value of text field 1 of group 1 of tool bar 1 of window 1 to toFind
delay 0.5 -- wait for Sys Events to get to the right place before clicking.
(* Search windows blindly (and annoyingly) default to "This Mac" for searches instead of to the folder that is open in the window so we need to select the folder button (labeled with its name). The search bar just below the title bar of the window is a "splitter group" because it has more than one section: "This Mac" and the "Folder Name" buttons in group 1, and "Contents" and "File Name" buttons in group 2 of the splitter bar. *)
-- click on the folder name button (radio button 2) in the first group of the splitter bar.
click radio button 2 of radio group 1 of group 1 of group 1 of splitter group 1 of window 1
-- now click the content or file name radio button as chosen. These form the second radio group of group 1 of group 1 of the splitter group just above the listing with the first being Content and the second labeled File Name.
if Btn contains "File" then click radio button 2 of radio group 2 of group 1 of group 1 of splitter group 1 of window 1 -- it defaults to "Content" so do nothing for that, and nothing bad happens if we click it again for Applications.
set B to button returned of (display dialog "Do you want to save this search?" buttons {"Cancel", "No", "Save"} default button "Save")
if B is "Save" then click button 2 of group 1 of group 1 of splitter group 1 of window 1
end tell
end tell