I don’t know much AppleScript at all, but managed to cobble together a script (invoked with Alfred) that opens a Finder window, sets the size, view options etc. and searches for Photoshop documents with the term passed from Alfred.
As it’s cobbled together I’m guessing there are much cleaner, efficient, and more elegant ways of doing this. Any help cleaning it up would be greatly appreciated. Here’s the script:
set q to "wobbly jelly" -- Test search
-- on alfred_script(q)
set theSearch to q
tell application "Finder"
activate
open computer container
-- Set the folder view
tell Finder window 1
set the bounds to {630, 150, (630 + 1300), (150 + 1100)}
-- window width=1300, window height=1100, space either side=630, height from top=150
set toolbar visible to true
set the sidebar width to 180
end tell
end tell
tell application "System Events"
-- Focus to the search field
keystroke "f" using {command down, option down}
delay 0.4
-- Type the search
keystroke "kind:photoshop " & theSearch
end tell
-- Arrange by.
menu_click({"Finder", "View", "Arrange By", "Date Modified"})
-- Set to Icon View
tell application "Finder"
set current view of Finder window 1 to icon view
tell icon view options of Finder window 1
set icon size to 128
set shows icon preview to true
set shows item info to true
end tell
end tell
-- end alfred_script
-- `menu_click`, by Jacob Rus, September 2006
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse