Page 1 of 1
Iso or not iso source ?
Posted: Mon May 12, 2014 8:57 am
by jmburnod
Hi All,
I am cooking a way to know on which platform a text file was created.
This script seems work but I guess someone have a better solution.
Code: Select all
on mouseUp
answer file "Open"
if it = empty then exit mouseUp
put url("file:" & it) into tText
put mactoIso(numtochar(142)) into tSearchFrench
put mactoIso(numtochar(138)) into tSearchGerman
if matchText(tText,tSearchFrench) or matchText(tText,tSearchGerman) then
put "Iso" into tSource
else
put "Mac" into tSource
end if
answer "This file was created on" && tSource
end mouseUp
Thank for comment
Jean-Marc
Re: Iso or not iso source ?
Posted: Mon May 12, 2014 6:27 pm
by Klaus
Hi Jean-Marc,
on the mac you could use a shell command!
file -I <path_to_file.txt>
Gives me this for a ISO encoded text file:
/Users/klaus/Desktop/videos_alexa.txt: text/plain; charset=iso-8859-1
Hope this helps!
Best
Klaus
Re: Iso or not iso source ?
Posted: Mon May 12, 2014 10:11 pm
by jacque
I wonder if it would be reliable to just check the line endings.
numToChar(13) = Mac
numToChar(10) & numToChar(13) = Windows (LFCR)
numToChar(10) = Linux
But I'm not sure that would be consistent. If you are always on a Mac I think Klaus' shell command is reliable.
Re: Iso or not iso source ?
Posted: Mon May 12, 2014 11:21 pm
by jmburnod
Hi,
@Klaus
I never used shell commands and i'm confused about syntax
LC Dictionary only talks about function shell.
@ Jacque
If you are always on a Mac I think Klaus' shell command is reliable.
I need it for OSX,windows and Linux to allow files exchange between all platforms
( except from mac to androïd and IOS to windows)
numToChar(13) = Mac
numToChar(10) & numToChar(13) = Windows (LFCR)
There is two chars for the line ending on windows ?
Thanks for your lights
Jean-Marc
Re: Iso or not iso source ?
Posted: Tue May 13, 2014 12:02 am
by jacque
jmburnod wrote:
There is two chars for the line ending on windows ?
Yes.
But oops, I got it backwards. Windows line endings are CRLF.
Re: Iso or not iso source ?
Posted: Tue May 13, 2014 2:48 am
by paul_gr
jacque wrote:
Yes.
But oops, I got it backwards. Windows line endings are CRLF.
Not always.
I'm using Notepad++ as a text editor on Windows and have it setup to save line endings as LF.
This is fairly common if anyone is using a programmers editor.
Paul
Re: Iso or not iso source ?
Posted: Tue May 13, 2014 7:15 am
by jacque
Wondered about that. I wasn't sure how predictable the line endings would be. On my Mac I have BBEdit set to use Linux line endings, so I don't follow the norm either. So probably a shell command is a better deal if there is one available on each platform.
Re: Iso or not iso source ?
Posted: Sun Jun 08, 2014 10:45 am
by jmburnod
Hi All
So probably a shell command is a better deal if there is one available on each platform.
Sorry I dont know using Shell
I maybe have found a way working as Jacques has suggested

(All concerned files are created by my app)
Code: Select all
function getFileCreatePlatform pFile
put url ("binfile:" & pFile) into x
put "n/a" into LsepLine
put 0 into LBOMlength
if offset(numToChar(13)&numToChar(10),x) > 0 then
put "win" into LsepLine
else if offset(numToChar(10),x) > 0 then
put "unix" into LsepLine
else if offset(numToChar(13),x) > 0 then
put "mac" into LsepLine
end if
return LsepLine
end getFileCreatePlatform
Kind regards
Jean-Marc