Sunday, September 22, 2019

#1 2019-04-19 10:00:00 am

bplaney
Member
Registered: 2005-07-11
Posts: 2

Simple Spotlight Search script

I use Spotlight to check image files that are named after product SKUs.

I have searched the web for an AppleScript that can do nothing more than execute the search with the contents of the clipboard, but cannot find a solution.

All I need is a script that will paste the contents of the clipboard into the magnifying glass (Spotlight). That's it. I don't want to resort to involving keyboard commands that activate Spotlight, because I have too many other live macros on my system via Keyboard Maestro.

I plan to connect the script to a FileMaker button, and the action will be to copy the SKU from its field and execute the AppleScript that has Spotlight do the search.

I need to add that I only want to LOOK at the results - I do not want to do anything with them. A quick glance at what shows up is enough for my purposes.

thanks in advance for any help.

Model: MacPro 5,1
AppleScript: 2.5
Browser: Safari (12607.1.40.1.5)
Operating System: macOS 10.12

Last edited by bplaney (2019-04-19 11:50:59 am)

Offline

 

#2 2019-04-19 06:07:32 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5900

Re: Simple Spotlight Search script

bplaney wrote:

All I need is a script that will paste the contents of the clipboard into the magnifying glass (Spotlight).



Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set theWord to the clipboard as text
current application's NSWorkspace's sharedWorkspace()'s showSearchResultsForQueryString:theWord


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-04-24 05:39:07 pm

bplaney
Member
Registered: 2005-07-11
Posts: 2

Re: Simple Spotlight Search script

Shane Stanley wrote:
bplaney wrote:

All I need is a script that will paste the contents of the clipboard into the magnifying glass (Spotlight).



Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set theWord to the clipboard as text
current application's NSWorkspace's sharedWorkspace()'s showSearchResultsForQueryString:theWord




THANK YOU SHANE!
It works wonderfully. I added a dot in the search, so that it would only find actual image files, whether they ended in .jpg, or .png or .psd or .tif, so the final line now reads:

current application's NSWorkspace's sharedWorkspace()'s showSearchResultsForQueryString:(theWord & ".")

regards,
Bill

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)