Jump to content

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

UNIX / DOS Text Files


  • Please log in to reply
7 replies to this topic
beardboy
  • Members
  • 443 posts
  • Last active: May 27 2017 08:41 AM
  • Joined: 02 Mar 2004
I have a UNIX Text file that I am modifying by using FileReadLine, and FileAppend. When using FileAppend it converts the UNIX file to a DOS file which my 3rd Party Application can not read.

I use metapad as a text editor and can open the file in that program and convert it back to UNIX, just wondering if there is a way that I'm not aware of to convert the file to UNIX, or to leave the format of the file the same?

thanks,
beardboy

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
This is actually more a limitation of Windows than of AutoHotkey per se. Unix uses only a linefeed (LF) character as its "newline", while Windows uses CR+LF. But because AutoHotkey writes to files using text mode, the newline character (`n) is automatically converted to CR+LF by C++ and/or Windows itself.

What I might be able to do is add a directive such as #FileWriteBinary, which would cause FileAppend to treat a `n as if it were only an LF rather than a CR+LF. I think this is an easy change, so I can send you a changed version right away if you'd like to test it out.

beardboy
  • Members
  • 443 posts
  • Last active: May 27 2017 08:41 AM
  • Joined: 02 Mar 2004
If it is an easy change then yes I would like to test it out.

thanks,
beardboy

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Ok, give this version a try (I tested it and it seems to work as expected).

Edit: Here's the full installer (someone asked for it):
http://www.autohotke...Hotkey1004a.exe

or just the main program if you prefer:
http://www.autohotke...Hotkey1004a.zip
(overwrite your installed EXE with the one in the zip file)


Currently, the #FileWriteBinary directive is global, meaning that it affects the entire script -- regardless of where it appears in the script -- and you can't turn it off or on during runtime. If you need to be able to do this, let me know so I can change it to some other method before it becomes an official change.

I would've added it as a param to the FileAppend command, but this is difficult to do without breaking current scripts (due to non-escaped commas in the last parameter).

Here are the changes in the above version so far:

Fixed Ctrl-Alt-Delete on Windows NT/2000 so that Ctrl and Alt aren't thought to be down upon returning. [thanks Julian Doak]

Fixed GetKeyState so that the physical state of the mouse buttons is properly reported when the mouse hook is installed.

Fixed StringLower so that it accepts the optional Title-Case parameter as intended. [thanks beardboy]

Changed clipboard handling so that the program will keep trying to open the clipboard for 800 vs. 400 milliseconds before giving up and displaying a warning dialog. [thanks Jason Payam Ahdoot]

Added support for {SLEEP} to the Send command. Also added SLEEP as an allowed hotkey, though the Sleep button on some keyboards might not be compatible with this.

Added built-in variable %A_Index%, which is the number of the current loop iteration. The first iteration is 1, the second is 2, etc.

Added built-in variable %A_IdleTimePhysical%, which is similar to %A_IdleTime% except that it ignores artificial input (that generated by scripts and programs), and thus may be more useful for detecting whether the user is truly present. This variable will be the same as %A_IdleTime% unless the keyboard or mouse hook (or both) is installed.

Added a directive #FileWriteBinary, which directs FileAppend to write in binary vs. text mode. As far as I know, the only consequence of this is that newline (`n) will be written as an isolated linefeed (LF) rather than a carriage return + linefeed (CR+LF).

beardboy
  • Members
  • 443 posts
  • Last active: May 27 2017 08:41 AM
  • Joined: 02 Mar 2004
New Version works perfectly with what I needed. I was having to open a text file that was bigger than 5 MB in a text editor and then convert it to UNIX and resave the file. Much easier, thank you.

As far as a different method it would be nice to be able to do both in one script. Maybe have a Parameter of On or Off to turn it on and then turn it back off would be nice.

#FileWriteBinary On
FileAppend, Text, c:\unix.txt
#FileWriteBinary Off
FileAppend, Text, c:\dos.txt
thanks,
beardboy

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I was thinking about this a bit more. I think it might be better to make the DOS/Unix part of the command after all. For example:

FileAppend, text, *C:\Unix.txt

Perhaps the asterisk prefix, or some other char that's illegal in filenames, can be used to indicate binary mode.

beardboy
  • Members
  • 443 posts
  • Last active: May 27 2017 08:41 AM
  • Joined: 02 Mar 2004
A prefix character would be nice, less lines of code. :)

thanks,
beardboy

beardboy
  • Members
  • 443 posts
  • Last active: May 27 2017 08:41 AM
  • Joined: 02 Mar 2004
Chris,

Just wanted to tell you that the latest version with the asterisk prefix worked great and helped alot.

Thanks again for the quick response and change,
beardboy