Panay.is Posted April 1, 2015 Share Posted April 1, 2015 (edited) I'm extremely new to applescript and alfred for that matter so I have absolutely no idea if this is going the right way or not.So far I've managed to get applescript to take a predefined file (URL given to it by me before hand) have it load into chrome and then use chromes right click->search by image function. Any advice would be appreciated on how to take it further! The next step in my mind is trying to work out how on earth to get alfred to pass a file into the script! It's very a gritty script but it's finally working at least >,< set myFile to "file:///Users/admin/Desktop/Google%20Drive/Applescript/ReverseSearch/photo.jpg" --do not move mouse while this is running activate application "Google Chrome" tell application "System Events" to tell process "Google Chrome" delay 1 set the clipboard to myFile keystroke "t" using command down keystroke "v" using command down key code 36 delay 2 do shell script "/Users/admin/cliclick kd:ctrl c:700,500 ku:ctrl" delay 1 do shell script "/Users/admin/cliclick c:766,590" delay 1 end tell --close image opened in previous Chrome tab tell application "Google Chrome" set windowList to every tab of every window whose URL starts with "file://" repeat with tabList in windowList set tabList to tabList as any repeat with tabItr in tabList set tabItr to tabItr as any delete tabItr end repeat end repeat end tell NOTE: Cliclick must be located in home for the right click to work and the browser has to be in the middle of the screen currently while I work on calculating the bounds of the users browser and finding the top left most corner of the image for the right click to be effective! Edited April 1, 2015 by Panay.is Link to comment
jdfwarrior Posted April 2, 2015 Share Posted April 2, 2015 I'm extremely new to applescript and alfred for that matter so I have absolutely no idea if this is going the right way or not. So far I've managed to get applescript to take a predefined file (URL given to it by me before hand) have it load into chrome and then use chromes right click->search by image function. Any advice would be appreciated on how to take it further! The next step in my mind is trying to work out how on earth to get alfred to pass a file into the script! It's very a gritty script but it's finally working at least >,< set myFile to "file:///Users/admin/Desktop/Google%20Drive/Applescript/ReverseSearch/photo.jpg" --do not move mouse while this is running activate application "Google Chrome" tell application "System Events" to tell process "Google Chrome" delay 1 set the clipboard to myFile keystroke "t" using command down keystroke "v" using command down key code 36 delay 2 do shell script "/Users/admin/cliclick kd:ctrl c:700,500 ku:ctrl" delay 1 do shell script "/Users/admin/cliclick c:766,590" delay 1 end tell --close image opened in previous Chrome tab tell application "Google Chrome" set windowList to every tab of every window whose URL starts with "file://" repeat with tabList in windowList set tabList to tabList as any repeat with tabItr in tabList set tabItr to tabItr as any delete tabItr end repeat end repeat end tell NOTE: Cliclick must be located in home for the right click to work and the browser has to be in the middle of the screen currently while I work on calculating the bounds of the users browser and finding the top left most corner of the image for the right click to be effective! How are you wanting to trigger this? A keyword? A hotkey? Different methods have different ways of setting this up. a) Hotkey - You would simply setup a workflow that had your script in a "Run Script" object and change where you set the path to myfile to be: set myfile to "file://{query}" You would need to make sure that the hotkey trigger was set to pass the current osx select to the next step and connect the hotkey to the run script. Keyword - Similar to above except you would use the keyword to run your applescript and use the applescript to grab the currently selected object within finder. c) Result Action - This is when you select a file within Alfred and then press the right arrow to get a list of actions to perform on the file. Here you would add a Result Action item into the workflow, name it and connect it to the Run Script as well. The file path would be passed to the Run Script the same as the other methods. Does that help? Link to comment
Panay.is Posted April 2, 2015 Author Share Posted April 2, 2015 Keyword - Similar to above except you would use the keyword to run your applescript and use the applescript to grab the currently selected object within finder. Been trying to get that part to work all day didn't even think of getting Finder to do it itself Just set it up as a workflow and ran it through Alfred for the first time.... That unbelievably awesome feeling of seeing it work how it was intended to work Time to tidy it up Thank you!! I do have one more question i'm struggling to find an answer to deep in the forums - with cliclick is there a particular way to reference to it if I store it within the workflow folder? Link to comment
Panay.is Posted April 2, 2015 Author Share Posted April 2, 2015 (edited) Updated script for anyone who wishes to use it for themselves --Locate File user wishes to reverse searchtell application "Finder" set sel to the selection as text set the clipboard to POSIX path of sel end tell --perform search in Google Chrome activate application "Google Chrome" tell application "System Events" to tell process "Google Chrome" delay 1 keystroke "t" using command down keystroke "v" using command down key code 36 delay 1.5 set myBounds to bounds of window 1 of application "Google Chrome" set x to item 1 of myBounds set y to item 2 of myBounds do shell script "/Users/admin/cliclick m:" & x & "," & y & "w:100 kd:ctrl c:+2,+74 ku:ctrl w:1000 c:+66,+90 w:700" end tell --close file tab google chrome leaving only search result open tell application "Google Chrome" set windowList to every tab of every window whose URL starts with "file://" repeat with tabList in windowList set tabList to tabList as any repeat with tabItr in tabList set tabItr to tabItr as any delete tabItr end repeat end repeat end tell NOTE: As before cliclick must be installed in User/home/.. for the right click to work Chrome needs to be installed and preferably active in the dock due to this script being based on action delays. Annd as the workflow uses cliclick to emulate clicks within chrome to reverse search the image - moving the mouse while the workflow is going will more often than not result in *right-click* “Search Google by Image” failing.EDIT: Included in the form of a workflow export http://cl.ly/0u3Y2P1q2L43 Edited April 2, 2015 by Panay.is Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now