StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 Save Image in Browser
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

harnas666

2 Posts

Posted - 07/11/2015 :  11:48:50  Show Profile  Reply with Quote
Hi,

I'm curious if there's some script to save image to default location in browsers Chrome/Firefox with StrokesPlus? Both FireGestures and SmoothGestures extensions support it.

Thank you in advance.

Rob

USA
2573 Posts

Posted - 07/12/2015 :  22:23:49  Show Profile  Visit Rob's Homepage  Reply with Quote
Well, it's a little trickier with automation software like S+ because it doesn't run within the domain of the application (e.g. Chrome). An extension runs within Chrome and therefore has access to functionality exposed to the extension by Chrome, such as the HTML and images, etc. With automation software, you don't have that access, so the only way to accomplish something like that is the play the keyboard/mouse movements necessary to emulate what you would do to achieve the same result.

For example, this script works for me. Note, however, that the assumption is that when you right-click an image, the Save image as... menu item is the first item in the popup menu otherwise you'd need to tweak it further. Also note that this script temporarily consumes ALL physical keyboard and mouse input, so if your script has something wrong and crashes in the middle, you'll have to manually power off and reboot the computer because you won't be able to interact with anything. The reason for this disabling of input is to ensure that a slight (even 1 pixel) movement from your mouse doesn't affect the playback of the script.
acConsumePhysicalInput(1) --tells S+ to capture and discard ALL mouse and keyboard input
acMouseMove(gsx,gsy) --Move the mouse to where the gesture started
acDelay(20) --brief pause
acMouseClick(gsx, gsy, 0, 1, 1)  --Send the right mouse click above the image
acSendKeys("{DOWN}~") --Send the Down key once to select the first menu item, then send Enter (~)
acDelay(200) --Wait 200ms for the file dialog to appear, if your drive/PC is slow, increase this
acSendKeys("^x") --Send CTRL+X to cut the file name from the Save dialog
acSendKeys("{DELAY=10}D:\\OneDrive\\Pictures\\FromChrome\\~") --Type the desired file path and send Enter
acSendKeys("^v~") --Send CTRL+V to paste the original name of the file and send Enter
acMouseMove(gex,gey) --Move the mouse back to where it was when you finished the gesture
acConsumePhysicalInput(0)  --Enable mouse and keyboard input
Also, it's important to escape the folder location as above (D:\\OneDrive\\...); you MUST use two backslashes when referring to a single backslash (it's a programming thing, Google "Lua escape chars").

It's not the most ideal solution, but the only other way would be to find some other browser extension that lets you send a keystroke or something to perform the action within Chrome and have S+ send the keystroke. However, with many possible images on a page, I could see that not being practical.
Go to Top of Page

Rob

USA
2573 Posts

Posted - 07/12/2015 :  22:38:13  Show Profile  Visit Rob's Homepage  Reply with Quote
It looks like a better approach is to replace:
acSendKeys("{DOWN}~") --Send the Down key once to select the first menu item, then send Enter (~)
With:
acSendKeys("v") --Send the V key (seems to select the Save image as... menu item)
This way, if you gesture over an image which is linked to a URL, it won't select the first menu item of Open Link in New Tab.
Go to Top of Page

harnas666

2 Posts

Posted - 07/13/2015 :  09:49:31  Show Profile  Reply with Quote
Rob it works like a charm! I've already tried to make similar script with AutoHotkey but your way is a lot better, the only thing I had to change is replace:

acSendKeys("v")

with:

acSendKeys("f")

but it concerns only my particular case (Polish language version of Chrome). Thank you one more time for the tip and awesome tool as StrokesPlus is.
Go to Top of Page

Rob

USA
2573 Posts

Posted - 07/13/2015 :  09:51:46  Show Profile  Visit Rob's Homepage  Reply with Quote
Glad to hear, you're very welcome!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000