You are not logged in.
Hi all...
After communication to Nigel about the encoding of specific characters on macscripter.net.
I was doing some research on the topic.
And macscripter.net is not alone of strange character or broken encoding in UTF-8.
Before FluxBB or php use CP1252 or MS-ANSI WINDOWS-1252 to decode character.
When FluxBB change to UTF-8 the conversion of some character got broken.
But...
Apple include command-line tool iconv to be able to encode characters from one format to other.
Applescript:
-- Nigels current application reference character
set inputString to "⌘"
set theCommand to "iconv -f UTF-8 -t CP1252"
set theResult to do shell script "echo " & quoted form of inputString & "| " & theCommand
And maybe Apple have function to do it with ASOC. But the above AS Script will give you some
clue if you need to covert 'some' characters in AS from macscripter.net to UTF-8.
Regards.
Last edited by Fredrik71 (2020-07-28 06:35:27 am)
if you are the expert, who will you call if its not your imagination.
Offline
And maybe Apple have function to do it with ASOC.
Applescript:
use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use scripting additions
my convertFromCP1252:"⌘"
on convertFromCP1252:aString
set aString to current application's NSString's stringWithString:aString
set theData to aString's dataUsingEncoding:12 -- NSWindowsCP1252StringEncoding
return (current application's NSString's alloc()'s initWithData:theData encoding:4) as text -- NSUTF8StringEncoding
end convertFromCP1252:
Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com
Offline
Wonderful Shane...
A good start for a ASOC Script that take input of file... or take the text from Script Editor that has broken characters and convert it to correct ones. Many scripts on macscripter.net before 2010 but also before 2016 has them.
Good work Shane... thanks.
if you are the expert, who will you call if its not your imagination.
Offline
I made a fast Script that take the front document of Script Editor and encode the input
and make a new document. And I'm sure it could me adapted to work also for Script Debugger.
The Script use Script Menu...
Applescript:
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
on run
tell application "Script Editor"
tell front document to set theText to its contents
end tell
set convText to my convertFromCP1252:theText
tell application "Script Editor"
make new document with properties {text:convText}
end tell
end run
on convertFromCP1252:aString
set aString to current application's NSString's stringWithString:aString
set theData to aString's dataUsingEncoding:12 -- NSWindowsCP1252StringEncoding
return (current application's NSString's alloc()'s initWithData:theData encoding:4) as text -- NSUTF8StringEncoding
end convertFromCP1252:
Last edited by Fredrik71 (2020-07-28 08:58:22 am)
if you are the expert, who will you call if its not your imagination.
Offline
Thanks for the scripts, Fredrik71 and Shane. I've made this topic "sticky" so that it always appears near the top of the listing.
NG
Offline
Here is a Script that do the same thing but here we could select any text from Safari
to be converted to right characters.
Test site
https://macscripter.net/viewtopic.php?p … 76#p138776
Selected text on the post above.
Run the Script below.
Applescript:
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
on run
tell application "Safari"
activate
set theText to (do JavaScript "getSelection().toString()" in document 1)
end tell
set convText to my convertFromCP1252:theText
tell application "TextEdit"
make new document with properties {text:convText}
end tell
end run
on convertFromCP1252:aString
set aString to current application's NSString's stringWithString:aString
set theData to aString's dataUsingEncoding:12 -- NSWindowsCP1252StringEncoding
return (current application's NSString's alloc()'s initWithData:theData encoding:4) as text -- NSUTF8StringEncoding
end convertFromCP1252:
if you are the expert, who will you call if its not your imagination.
Offline