Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

SavePictureAs - (Save Image/Picture)


  • Please log in to reply
66 replies to this topic
randomguy
  • Members
  • 94 posts
  • Last active: Oct 20 2017 11:11 PM
  • Joined: 30 Oct 2011
sometimes it displays the SaveAs dialog box twice, one closes quickly with the image saved and one just stay there

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

Somehow it does the rightclicking and save as for me, but it always saves in Chrome's Default saveto folder


I changed the code some.

Added CoordMode, mouse , Screen
Now after the Lbutton is pressed the script waits for the Lbutton to be released using Keywait before it gets the x-y coordinates on release of the Lbutton.
I removed the GoSub to help troubleshoot.
I increased the sleep to 1000ms.
I moved the "Mouse moved up" code to the top.
I added to the "Timed out waiting for the Save As window to open" message to help you figure out why the message appeared.

I think increasing the sleep time will fix the issue with it saving to the default download folder incorrectly.

There are other issues like when you click and drag and you are not over an image. For instance while you are copy and pasting using the mouse. Also, when using the scroll bar by clicking on the scrollbar and moving the scrollbar up.

Try searching the forum for "detecting scrollbar under cursor".

Add that code under KeyWait,lbutton,UP then add RETURN.

Try this code
SetTitleMatchMode,1
LeftFolder = %a_desktop%\temp
RightFolder = %A_MyDocuments%\temp
CoordMode, mouse , Screen
return

~lbutton:: ;left button down
MouseGetPos,xd,yd ;get x and y coordinates
KeyWait,lbutton,UP
sleep 100
MouseGetPos,xu,yu ;get x and y coordinates
if (yd-yu) > 20 ;if ydown is greater then yup then mouse was moved up
 {
  sleep 1000
  Send {rbutton}
  Sleep, 1000
  send {v}
  WinWaitActive, Save,,5
  if errorlevel = 1
   {
   MsgBox Timed Out waiting for Save As window`n`nIf you are getting this error message then your mouse has moved more then 20 pixels up and the script was unable to right click and/or send v to open the Save As window. Maybe you released the mouse button when the cursor was not above the image.
   return
   }
 return
 }
if (xd-xu) > 20 ;if xdown is greater then xup, then mouse was moved left
 {
  sleep 1000
  Send {rbutton}
  Sleep, 1000
  send {v}
  WinWaitActive, Save,,5
  if errorlevel = 1
   {
   MsgBox Timed Out waiting for Save As window`n`nIf you are getting this error message then your mouse has moved more then 20 pixels to the left and the script was unable to right click and/or send v to open the Save As window. Maybe you released the mouse button when the cursor was not above the image.
   return
   }
  ControlgetText, Filename, Edit1, Save
  ControlSetText, Edit1,,Save
  ControlSetText,Edit1,%LeftFolder%\%FileName%,Save
  ControlClick , &Save, Save,,,,NA
  return
 }
if (xu-xd) > 20 ;if xup is greater then xdown then mouse was moved right
 {
  sleep 1000
  Send {rbutton}
  Sleep, 1000
  send {v}
  WinWaitActive, Save,,5
  if errorlevel = 1
   {
   MsgBox Timed Out waiting for Save As window`n`nIf you are getting this error message then your mouse has moved more then 20 pixels to the right and the script was unable to right click and/or send v to open the Save As window. Maybe you released the mouse button when the cursor was not above the image.
   return
   }
  ControlgetText, Filename, Edit1, Save
  ControlSetText, Edit1,,Save
  ControlSetText,Edit1,%RightFolder%\%FileName%,Save
  ControlClick , &Save, Save,,,,NA
  return
 }
return

Try using message boxes like below to troubleshoot.
ControlgetText, Filename, Edit1, Save 
  MsgBox retrieved %filename% from the Edit1 control
  ControlSetText, Edit1,,Save
  MsgBox erased Edit1 control
  ControlSetText,Edit1,%LeftFolder%\%FileName%,Save
  MsgBox set the value of the Edit1 control to %LeftFolder%\%FileName%
  ControlClick , &Save, Save,,,,NA 
  MsgBox check %LeftFolder% to see if image exists
Let me know how it works for you.
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

randomguy
  • Members
  • 94 posts
  • Last active: Oct 20 2017 11:11 PM
  • Joined: 30 Oct 2011
It's midnight now, I haven't tried the new script yet, but I would like to report something in the old script:


Somehow Chrome Save As dialog just "ignores" anything filled by the ControlSetText function, it only "listens" to what the user types in. I can see that the box is filled with the right information, yet when Save button is hit, it is still the old information that is saved

so this doesn't work
~lbutton::
MouseGetPos,xd,yd
return

~lbutton up::
FormatTime, CurrentDateTime1341,, yyyy-MM-dd_hhmmss ; It will look like 2011-10-27_123456
MouseGetPos,xu,yu
if (xd-xu) > 40
 {
  gosub,OpenSaveWindow
  TrayTip, Picture saved to %LeftFolder%, %CurrentDateTime1341% %FileName%, 1, 1
  ControlSetText,Edit1,%LeftFolder%\%CurrentDateTime1341% %FileName%,Save
  ControlClick , &Save, Save,,,,NA
.................(more of your script)

but this works:
~lbutton::
MouseGetPos,xd,yd
return

~lbutton up::
FormatTime, CurrentDateTime1341,, yyyy-MM-dd_hhmmss ; It will look like 2011-10-27_123456
MouseGetPos,xu,yu
if (xd-xu) > 40
 {
  gosub,OpenSaveWindow
  TrayTip, Picture saved to %LeftFolder%, %CurrentDateTime1341% %FileName%, 1, 1
  ControlSetText,Edit1,%LeftFolder%\%CurrentDateTime1341% %FileName%,Save
  send ^a
  sleep 30
  send ^c
  sleep 30
  send ^v
  sleep 30
  ControlClick , &Save, Save,,,,NA
.................(more of your script)


As you can see I have to add the "Select All", copy and then REPASTE lines to make Chrome realize that there is new information in the Filename field, otherwise even if ControlSetText has filled in the correct path and filenames, Chrome still save it like before (old name, old folder), as if the new path generated by ControlSetText that I see in the Filename field is an illusion!

randomguy
  • Members
  • 94 posts
  • Last active: Oct 20 2017 11:11 PM
  • Joined: 30 Oct 2011
I wonder why Chrome does not recognize the change of information input(ed) by the ControlSetText? this mystery really annoys me

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

I wonder why Chrome does not recognize the change of information input(ed) by the ControlSetText? this mystery really annoys me


I am using Chrome 15.0.874.121 and I do not have that behavior.

Try replacing controlsettext with
ControlFocus,edit1,Save
SendInput {Raw}%LeftFolder%\%FileName% ;leave no spaces between {Raw} and %LeftFolder%\ %FileName%

Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

randomguy
  • Members
  • 94 posts
  • Last active: Oct 20 2017 11:11 PM
  • Joined: 30 Oct 2011
strange, I use the same (latest) version. I will give a thorough testing tomorrow. Thanks!

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
It is noon here (Arkansas). Where are you?

I just remembered I had the same problem you are having a long time ago when I coded SavePictureAs.

I even documented it in my SavePictureAs.ahk code.

I am using SendInput {Raw} with SavePictureAs.ahk V6.3.

Here are the notes I put in SavePictureAs.ahk V6.3

;NOTES 1: Reason for using SendInput {Raw} instead of Send
;Send Car+Mustang+-+1999+Red+06 actually sends CarMustang_!999Red)6 (incorrect filename)
;SendInput {Raw} Car+Mustang+-+1999+Red+06 actually sends Car+Mustang+-+1999+Red+06 (exact filename match)
;NOTES 2: Reason for using SendInput {Raw} instead of ControSetText. When using some broswers on some OS's ControlSetText puts the text in the control but then when sending enter, alt s, or (ControlClick, &Save) to save the image it always tries to save the original filename without the new path. For example it continues to try to save - images.jpg instead of c:\NewPath\images.jpg This behavior is in windows vista and windows 7.


Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

randomguy
  • Members
  • 94 posts
  • Last active: Oct 20 2017 11:11 PM
  • Joined: 30 Oct 2011
so you are in the US, I am 12 hours away, in Vietnam. Trying to learn myself a bit of coding after a long time of just using others' products :roll: I really like AHK, in a sense that it is a standalone program itself but it can "integrate" into other programs as great compliments to make life much easier, no longer do we have to try to backup, transfer and restore things like macros (Word), or certain extension function (Firefox, Chrome), and more! We can also rename files, backup, check update, remind...It is universal, yet it is in one place. I find that I really need to learn a bit of this to customize things, so I'm really greatful to consult people like you. It seems that although AHK websites has a lack of interactive demos and visual guidance, but helpful and around the clock support from you guys really make up for it. Thanks again!

About your note, it is truly assuring to know that I'm not the only person with the hallucination :twisted:

Jaycephus
  • Members
  • 5 posts
  • Last active: Jan 22 2011 07:55 PM
  • Joined: 01 Jul 2010
So it is failing when I try to use this in Chrome.

At the check of what browser is being used, you look for 'Chrome_WidgetWin_0', but what is returned in my case is 'Chrome_WidgetWin_1'.

I can hard-code a simple fix for myself, but thought you might want to know.

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

So it is failing when I try to use this in Chrome.

At the check of what browser is being used, you look for 'Chrome_WidgetWin_0', but what is returned in my case is 'Chrome_WidgetWin_1'.

I can hard-code a simple fix for myself, but thought you might want to know.


thanks for the feedback.

I will change the code to check for both classes and update the download later.

What version of Chrome are you using?

I don't have chrome installed on this computer but I will check later to see if the class has changed.

thanks again
Datalife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
Version 6.5 uploaded.

Fixed Google Chrome window class issue found by Jaycephus.

thanks
DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

Neole
  • Guests
  • Last active:
  • Joined: --
Thank You! Just what i was looking for for chrome for many many months!!

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

Thank You! Just what i was looking for for chrome for many many months!!

I am glad you find my program useful.

Thanks for using it. I put alot of work into it.

DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

johnbatt
  • Members
  • 1 posts
  • Last active: Jul 22 2012 08:11 PM
  • Joined: 22 Jul 2012
That's pretty cool, I had a couple problems with it but it ended up working with Chrome in the end, with FF the zip files worked only, with IE there was a Save As dialog box 2 times and it saved on the second. Anyways it's working great with Chrome now thanks!

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

That's pretty cool, I had a couple problems with it but it ended up working with Chrome in the end, with FF the zip files worked only, with IE there was a Save As dialog box 2 times and it saved on the second. Anyways it's working great with Chrome now thanks!


Thanks for the report.

What OS are you using?

What version of Firefox?

I use SavePictureAs with Windows 7 and IE 9 and have no problems at all. It was originally written on Window XP but has not been tested on Windows XP in awhile.

thanks
DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.