Japanese or cyrillic characters in Growl via AppleScript
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
Japanese or cyrillic characters in Growl via AppleScript
hi folks!
i'm implementing growl notifications into a qt application (qt framework, not quicktime) at the moment, but the textencoding is worrying me. i know it's an apple script issue, but maybe someone here has already faced this problem.
we are receiving track information data from itunes and display it in the gui of the application correct, but i can't get them work with apple script. i know that apple script is usually working with mac roman encoding. so after generating the script into a qt qstring i convert it to utf8 to get it compiled and run - converting to mac roman isn't working. at the moment only western european special characters are working like umlauts or similar chars - japanese, chinese or cyrillic characters are still fucked up. what could i do to get this symbols working with apple script?
well thanks for any help in advance!
phil
i'm implementing growl notifications into a qt application (qt framework, not quicktime) at the moment, but the textencoding is worrying me. i know it's an apple script issue, but maybe someone here has already faced this problem.
we are receiving track information data from itunes and display it in the gui of the application correct, but i can't get them work with apple script. i know that apple script is usually working with mac roman encoding. so after generating the script into a qt qstring i convert it to utf8 to get it compiled and run - converting to mac roman isn't working. at the moment only western european special characters are working like umlauts or similar chars - japanese, chinese or cyrillic characters are still fucked up. what could i do to get this symbols working with apple script?
well thanks for any help in advance!
phil
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
Let me see if I have this correct....
You're converting the string from MacRoman -> UTF8 -> MacRoman?
I'd imagine the problem here is that the encoding translations are inserting encoding-specific characters not recognized in the various contexts you're attempting. Is there a specific reason you have to do this (I say this as an AS n00b [so simply say, bzzt... check the docs bgannin if needed], but given that Mac OS X itself really likes UTF(8 || 16) is there a reason you can't stick with it completely?)
You're converting the string from MacRoman -> UTF8 -> MacRoman?
I'd imagine the problem here is that the encoding translations are inserting encoding-specific characters not recognized in the various contexts you're attempting. Is there a specific reason you have to do this (I say this as an AS n00b [so simply say, bzzt... check the docs bgannin if needed], but given that Mac OS X itself really likes UTF(8 || 16) is there a reason you can't stick with it completely?)
Try my software!
#define ADIUMX pimp //by me
#define QUESTION ((2b) || (!2b))
Have you hugged a programmer today?
#define ADIUMX pimp //by me
#define QUESTION ((2b) || (!2b))
Have you hugged a programmer today?
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
I'll look into this a bit tonight to see if I can figure something out. I've been meaning to flesh out my AppleScript exposure anyway. This is against 0.7.6, correct?
Try my software!
#define ADIUMX pimp //by me
#define QUESTION ((2b) || (!2b))
Have you hugged a programmer today?
#define ADIUMX pimp //by me
#define QUESTION ((2b) || (!2b))
Have you hugged a programmer today?
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
I came across this thread that I thought may be relevant (they treated the string as data and then cast it to Unicode text basically)
http://bbs.applescript.net/viewtopic.ph ... action=new
http://bbs.applescript.net/viewtopic.ph ... action=new
Try my software!
#define ADIUMX pimp //by me
#define QUESTION ((2b) || (!2b))
Have you hugged a programmer today?
#define ADIUMX pimp //by me
#define QUESTION ((2b) || (!2b))
Have you hugged a programmer today?
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
thanks this hint sounds very useful, BUT now i have another problem: the script isn't compiling - i guess it's because of "»". when looking in my console output i get different characters instead of "«" and "»"...
Code: Select all
" notify with name \"Track Notification\" title \"" + metaData.track() +
"\" description «data utxt0020041B0435043D0438043D0433044004300434» as Unicode text"...
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
argh. now i've gotten these 2 symbols right and copy/paste from my console output into the script editor works fine. it isn't working when compiling/running the script from the program...
here are the apple script handling functions:
here are the apple script handling functions:
Code: Select all
OSAID LowCompileAppleScript( const void* text, long textLength )
{
// qDebug() << "Compiling script";
QString result;
OSStatus err;
AEDesc scriptTextDesc;
OSAID scriptID = kOSANullScript;
AECreateDesc( typeNull, NULL, 0, &scriptTextDesc );
/* put the script text into an aedesc */
err = AECreateDesc( typeUTF8Text, text, textLength, &scriptTextDesc );
if ( err != noErr )
goto bail;
/* compile the script */
err = OSACompile( theComponent, &scriptTextDesc, kOSAModeNull, &scriptID );
if ( err != noErr )
goto bail;
bail:
return scriptID;
}
/* LowRunAppleScript compiles and runs an AppleScript
provided as text in the buffer pointed to by text. textLength
bytes will be compiled from this buffer and run as an AppleScript
using all of the default environment and execution settings. If
resultData is not NULL, then the result returned by the execution
command will be returned as typeChar in this descriptor record
(or typeNull if there is no result information). If the function
returns errOSAScriptError, then resultData will be set to a
descriptive error message describing the error (if one is
available). */
bool LowExecAppleScript( OSAID scriptID, QString& resultToken )
{
// qDebug() << "Executing script";
QString s;
char result[4096] = "\0";
OSStatus err;
AEDesc resultData;
OSAID resultID = kOSANullScript;
// qDebug() << "Running script";
/* run the script/get the result */
err = OSAExecute( theComponent, scriptID, kOSANullScript, kOSAModeAlwaysInteract, &resultID );
// qDebug() << "Running script done" << err;
if ( err == errOSAScriptError )
{
OSAScriptError( theComponent, kOSAErrorMessage, typeUTF8Text, &resultData );
int length = AEGetDescDataSize( &resultData );
{
AEGetDescData( &resultData, result, length < 4096 ? length : 4096 );
result[ length ] = '\0';
s = QString::fromUtf8( (char *)&result, length );
LOG( 1, "AppleScript error: " << s << "\n" );
}
return false;
}
else if ( err == noErr && resultID != kOSANullScript )
{
// qDebug() << "Getting script result";
OSADisplay( theComponent, resultID, typeUTF8Text, kOSAModeNull, &resultData );
int length = AEGetDescDataSize( &resultData );
{
AEGetDescData( &resultData, result, length < 4096 ? length : 4096 );
s = QString::fromUtf8( (char*)&result, length );
// Strip surrounding quotes
if ( s.startsWith( "\"" ) && s.endsWith( "\"" ) )
{
s = s.mid( 1, s.length() - 2 );
}
// iTunes sometimes gives us strings with null terminators which
// fucks things up if we don't remove them.
while ( s.endsWith( QChar( QChar::Null ) ) )
{
s.chop( 1 );
}
// It also escapes quotes so convert those too
s.replace( "\\\"", "\"" );
}
}
else
{
// AppleScript not responding
return false;
}
// qDebug() << "Executing script done";
if ( resultID != kOSANullScript )
OSADispose( theComponent, resultID );
resultToken = s;
return true;
}
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
i would do, but i still have a problem - and i guess the situation is the same like before.
for test reasons i tried this script bgannin posted. i copied a song title from itunes and pasted the text into the dialog so that i get the code string out of it. then i put the encoded string («data utxt...» as Unicode text) into my selfwritten script generator and it worked fine with japanese and cyrillic signs. but now i've inserted the generated metadata into the script instead of the static encoded string i got from bgannin's script and it's the same problem like before...
now i've tried to convert the incoming data from mac roman to unicode, generating the script and convert the whole script to mac roman before compiling and executing... still not working...
for test reasons i tried this script bgannin posted. i copied a song title from itunes and pasted the text into the dialog so that i get the code string out of it. then i put the encoded string («data utxt...» as Unicode text) into my selfwritten script generator and it worked fine with japanese and cyrillic signs. but now i've inserted the generated metadata into the script instead of the static encoded string i got from bgannin's script and it's the same problem like before...

now i've tried to convert the incoming data from mac roman to unicode, generating the script and convert the whole script to mac roman before compiling and executing... still not working...
-
- Harmless
- Posts: 11
- Joined: Tue Mar 27, 2007 1:23 pm
problem solved now. REALLY! 
i wrote an own function which converts the special chars to hex:

i wrote an own function which converts the special chars to hex:
Code: Select all
QString
convertUnicodeToHex( QString string )
{
QString conversionReturn = QChar( 0x00AB );
conversionReturn += "data utxt";
for( int i = 0; i < string.length(); i++ )
{
QChar singleChar = string[i];
QString hexadecimal = QString( "%1" ).arg( (int)singleChar.unicode(), 0, 16 );
if( hexadecimal.length() == 1 ) hexadecimal.prepend("000");
if( hexadecimal.length() == 2 ) hexadecimal.prepend("00");
if( hexadecimal.length() == 3 ) hexadecimal.prepend("0");
conversionReturn += hexadecimal;
}
return conversionReturn + QChar( 0x00BB ) + " as unicode text";
}