Make home Library sub-folders available to Spotlight

Nov 29, '12 07:30:00AM

Contributed by: llee

Here's one approach to making items in your home Library folder searchable in Spotlight.

Spotlight searches exclude items that exist in the user's home Library folder (now hidden by default). There are some items that normally reside in the home Library folder that I want to be available for my Spotlight searches. Rather than trying to find a hack to defeat the system's exclusion of the home Library folder for Spotlight, I use a method that doesn't require crossing the boundaries of what the OS permits users to do.

I simply select folders, the contents of which I would like to appear in Spotlight searches, such as Scripts and Favorites, move them up a level to the home folder, then create a symbolic link to the moved item to serve as a substitute for it in its original location. I'm including source for an AppleScript droplet that I use to automate this process. If your Library folder is already open (one way to open it is to hold down the Option key then select it from the Go menu in the Finder), just drop one or more of its folders onto the droplet. If you double-click the droplet created from the AppleScript, it will open your Library folder so that you can drop one or more folders into the ensuing dialog box.

on open the_items
        my up_one_leave_link(the_items)
end open

on up_one_leave_link(the_items)
        display dialog "This will move dropped folders
up one directory and substitute symbolic links
that point to their new location.

Is that what you want to do?"
        repeat with the_item in the_items
                set the_item to the_item as alias
                tell application "Finder"
                        set sost to ((container of folder ¬
                                (the_item as string)) as alias) as string
                        set sost_Parent to (container of folder ¬
                                (sost as alias))
                end tell
                set sost to POSIX path of sost
                set sost_Parent to POSIX path of (sost_Parent as string)
                set this_filepath to (the_item as string)
                if last character of this_filepath is ":" then
                        tell me to set it_is_a_folder to true
                else
                        set it_is_a_folder to false
                end if
                set thesourcename to (name of (info for the_item))
                set the_source_file to POSIX path of this_filepath
                set pos_filepath to sost
                if it_is_a_folder then
                        try
                                set my_command to "mv" & ¬
                                        space & (quoted form of the_source_file) ¬
                                        & space & (quoted form of sost_Parent)
                                set my_command to my_command & ¬
                                        ";ln -s" & space & (quoted form of sost_Parent) ¬
                                        & (quoted form of thesourcename) & space & (quoted form of sost)
                                do shell script my_command
                        on error onerr
                                activate
                                display dialog onerr
                        end try
                else
                        display dialog "Folders only, please!"
                end if
        end repeat
end up_one_leave_link

on run
        display dialog "This will move selected folders
up one directory and substitute symbolic links
that point to their new location.

Is that what you want to do?"
        do shell script "open ~/Library"
        do shell script "sleep 1"
        activate
        set the_items to ((choose folder) as list)
        up_one_leave_link(the_items)
end run
[kirkmc adds: Paste the above script in AppleScript Editor, then save it as an application. This solution should work, but be careful if, after an OS X update, something is broken.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20121128100420347