Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

[Fixed] AHK_L often crashes when saving clipboard to a file


  • Please log in to reply
18 replies to this topic
TomXIII n-l-i
  • Guests
  • Last active:
  • Joined: --
[Moderator's note: Moved from Ask for Help to Bug Reports.]

Hi everyone!

I have a problem with this portion of code. AutoHotkey_L often crashes with this part of code!
It saves the clipboard to a file
!c::
Clipboard := ""
Send, ^c
ClipWait, 5
If !Clipboard
	Return
InputBox, FileName, Save Clipboard:, File name ?,, 250, 140
If (!FileName || ErrorLevel )
	Return
Path := A_ScriptDir "\" FileName ".txt"
FileDelete, %Path%
FileAppend, %ClipboardAll%, %Path%


emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009
could you do a sleep between filedelete and fileappend?
see if that helps

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
No need for filedelete, see docs: a fileappend, %clipboardall% automatically deletes the file if present.

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
Where exactly does it crash?

TomXIII
  • Members
  • 182 posts
  • Last active: Feb 28 2011 11:42 PM
  • Joined: 14 Apr 2009
I think it crashes with FileAppend and may be with big contents.
If I save the clipboard with simple plain text, it works fine but if I try to save a selection in Word (text, formula, table), it crashes!

For more details, I use this part of code to store formulas and paste them with Regex hotstrings

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
I am able to reproduce the problem copying an equation from Word

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
It seems that Office programs do not play well with AHK in this regard. I think I found a workaround, though:

temp := ClipboardAll
FileDelete, %Path%
FileAppend, %temp%, %Path%

Try that instead. Saving the entire clipboard to a variable first seems to work better.

TomXIII
  • Members
  • 182 posts
  • Last active: Feb 28 2011 11:42 PM
  • Joined: 14 Apr 2009
@Rapte_Of_Suzaku: Sorry for my English but you mean you have the same problem?! I'm trying your solution.

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
All I meant was: I successfully got the same problem to happen on my computer. If I can't first get the problem to happen on my computer, it is harder to find the solution.

TomXIII
  • Members
  • 182 posts
  • Last active: Feb 28 2011 11:42 PM
  • Joined: 14 Apr 2009
I tried your solution, it still crashes but less!
I think this is a problem with Word because with Writer (open office) it never crashes!
Even if it works with Writer, I would it to work also with Word!

Edit: With Writer I save a clipboard with formula, table, graphics and pictures and no problems!

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
You might consider posting this in the bug report section now. It may be Word's fault, but it feels like a bug to have AHK crash.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Which Office version do you use?

It seems to work fine for me (Office 2003SP3)

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
I'm using 2010

TomXIII
  • Members
  • 182 posts
  • Last active: Feb 28 2011 11:42 PM
  • Joined: 14 Apr 2009
I'm using Office 2007 and Open Office 3
The solution of Rapte_Of_Suzaku reduce the crash.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
It seems that AutoHotkey (any version) assumes that GetClipboardData(format) will return a handle to a block of memory. This naive approach works for the most part since GlobalSize() fails when it is given an invalid handle, causing unsupported formats to be skipped over. During my testing, the crashes occurred when trying to call GlobalSize() with a handle returned by GetClipboardData(CF_ENHMETAFILE). Sometimes it crashed, sometimes it merely returned error 6 (ERROR_INVALID_HANDLE).

Reading Standard Clipboard Formats, it appears that at least the following formats should not be interpreted as memory handles: CF_BITMAP, CF_ENHMETAFILE and (probably) CF_DSPENHMETAFILE. It might be sufficient to simply skip these formats. I need to review the other uses of ClipboardAll before I attempt a bug-fix.

I've moved the thread to Bug Reports.