Using danish char's

Hello People…
So this is driving me crasy, i need to use æøå in a text string…

the string is like this " Grønne slagtere " and will be set as " Grønne+slagtere " for use in a search script
but t i’m getting these chars…

%BF = ø
%BE = æ
%8C = å

is there a function or something to convert all this in one go…

currenlty using 3 functions for this :frowning:


on parseChars(this_string)
	set s to "%BF"
	set r to "ø"
	set utid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {s}
	set temp_list to text items of this_string
	set AppleScript's text item delimiters to {r}
	set this_string to temp_list as string
	set AppleScript's text item delimiters to utid
	return this_string
end parseChars

but if the word contains more than one of the special chars i get in truble…

really need some help here…

/mkh

If there is more than one element to treat you have to consider a loop…

… try this …

property l1 : {"%BF", "%BE", "%8c"}
property l2 : {"ø", "æ", "å"}

to Substitute(search, replace, myText)
	script o
		property __s : search
		property __r : replace
		property __t : myText
	end script
	
	set TIDs to AppleScript's text item delimiters
	repeat with i from 1 to count o's __s
		set AppleScript's text item delimiters to o's __s's item i
		set o's __t to o's __t's text items
		set AppleScript's text item delimiters to o's __r's item i
		set o's __t to o's __t as text
	end repeat
	set AppleScript's text item delimiters to TIDs
	
	return o's __t
end Substitute


Substitute(l2, l1, "Et øjeblik!... Værsgo! For det første er igangværende direkte , så er der ikke mere gyrate til højre og der har vi det hitte en oversætter!")
--> Result: Et %BFjeblik!...V%BErsgo!  For det f%BFrste er igangv%BErende direkte , s%8c er der ikke mere gyrate til h%BFjre og der har vi det hitte en overs%BEtter!


--Substitute(l1, l2, result)
--> Result: Et øjeblik!... Værsgo! For det første er igangværende direkte , så er der ikke mere gyrate til højre og der har vi det hitte en oversætter!

Regards
Clement

Thx, but im not getting any other info than i did have before, so either im using this wrong, or this is not working…

tryed use it like this…


property l1 : {"%BF", "%BE", "%8c"}
property l2 : {"ø", "æ", "å"}

set myText to Substitute(l2, l1, "Et %BFjeblik")
display dialog myText

to Substitute(search, replace, myText)
	script o
		property __s : search
		property __r : replace
		property __t : myText
	end script
	
	set TIDs to AppleScript's text item delimiters
	repeat with i from 1 to count o's __s
		set AppleScript's text item delimiters to o's __s's item i
		set o's __t to o's __t's text items
		set AppleScript's text item delimiters to o's __r's item i
		set o's __t to o's __t as text
	end repeat
	set AppleScript's text item delimiters to TIDs
	
	return o's __t
end Substitute

ARGH :O) got it to work, just need some coffe and a break :slight_smile:

Okay, this i kinda weird, when i use the above script in Script Editor all is fine, but as soon i try to use it in my application, nothing happens…

The problem is i need to convert items “æøå” to url like this " http://imdb.com/find?s=all&q=de+gr�nne+slagtere " which is working in script editor :frowning:

here are the part where it is ment to be used…


on imdbSearch(imdb_title)
	
	set myTitle to parseSpecialChars(l2, l1, imdb_title)
	set imdb_title to my parseSearchUrl(myTitle)
	set imdb_search_url to "http://www.imdb.com/find?s=tt&q="
	
	try
		try
			set imdb_search_result to do shell script "curl -w \"%{url_effective}\" " & "'" & imdb_search_url & "" & imdb_title & "' | grep -i \"exact matches\""
		on error
			set imdb_search_result to do shell script "curl -w \"%{url_effective}\" " & "'" & imdb_search_url & "" & imdb_title & "' | grep -i \"Approx Matches\""
		end try
	on error
		tell progress indicator "spinner" of window "IMDB Search" to stop
		return
	end try
       
       -- The rest of the script is not importent as this point since the above part is not working....


The propertys should be in place and i’ve tryed debugging a bit, but not with any luck,


to parseSpecialChars(search, replace, myText)
	script o
		property __s : search
		property __r : replace
		property __t : myText
	end script
	
	set TIDs to AppleScript's text item delimiters
	repeat with i from 1 to count o's __s
		set AppleScript's text item delimiters to o's __s's item i
		set o's __t to o's __t's text items
		set AppleScript's text item delimiters to o's __r's item i
		set o's __t to o's __t as text
	end repeat
	set AppleScript's text item delimiters to TIDs
	
	return o's __t
	
end parseSpecialChars

on parseSearchUrl(movie_title)
	set text item delimiters to "."
	set imdb_url to text items of movie_title
	set text item delimiters to space
	set imdb_url to imdb_url as Unicode text
	set text item delimiters to "_"
	set imdb_url to text items of imdb_url
	set text item delimiters to space
	set imdb_url to imdb_url as Unicode text
	set imdb_url to text items of imdb_url
	set text item delimiters to "+"
	set imdb_url to imdb_url as Unicode text
	set text item delimiters to ""
	return imdb_url
end parseSearchUrl

Hi,

Here you can find Apple’s subroutines for URL encoding and decoding

PS: short version


set a to "Et %BFjeblik!...V%BErsgo! For det f%BFrste er igangv%BErende direkte , s%8c er der ikke mere gyrate til h%BFjre og der har vi det hitte en overs%BEtter!"
do shell script "perl -e 'use URI::Escape; print uri_unescape(\"" & a & "\")';"
--> Et øjeblik!...Værsgo! For det første er igangværende direkte , så er der ikke mere gyrate til højre og der har vi det hitte en oversætter!

Ah, Stefan this is great, the perl part is super, is there a way to convert the other way, which is the main problem…

And btw i have the same script in plain scpt file to show the same data in a dialog, and this is working, so i really dont
get why it stops when i put it in my app :confused:

unfortunately the opposite perl routine uses utf-8


set b to "Et øjeblik!...Værsgo! For det første er igangværende direkte , så er der ikke mere gyrate til højre og der har vi det hitte en oversætter!"
do shell script "perl -e 'use URI::Escape; print uri_escape(\"" & b & "\")';"
--> Et%20%C3%B8jeblik!...V%C3%A6rsgo!%20For%20det%20f%C3%B8rste%20er%20igangv%C3%A6rende%20direkte%20%2C%20s%C3%A5%20er%20der%20ikke%20mere%20gyrate%20til%20h%C3%B8jre%20og%20der%20har%20vi%20det%20hitte%20en%20overs%C3%A6tter!

so you can use the quite flexible Apple routines

[i]TEXT ENCODING SUB-ROUTINE
This sub-routine is used in conjunction with the encoding characters sub-routine to encode spaces and high-level ASCII characters (those above 127) in passed text strings. There are two parameters which control which characters to exempt from encoding.

The first parameter: encode_URL_A is a true or false value which indicates to the sub-routine whether to also encode most of the special characters reserved for use by URLs.
The second parameter: encode_URL_B is false, thereby exempting periods (.), colons(:), underscores (_), and hypens (-) from encoding

In the following example the encode_URL_A value is false thereby exempting the asterisk (*) character, which has a special meaning in URL’s, from the encoding process. Only spaces and high-level ASCII characters, like the copyright symbol are encoded.
[/i]

encode_text("*smith-wilson© report_23.txt", false, false)
--> "*smith-wilson%A9%20report_23.txt"

-- this sub-routine is used to encode text 
on encode_text(this_text, encode_URL_A, encode_URL_B)
 set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
 set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
 set the URL_B_chars to ".-_:"
 set the acceptable_characters to the standard_characters
 if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
 if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
 set the encoded_text to ""
 repeat with this_char in this_text
 if this_char is in the acceptable_characters then
 set the encoded_text to (the encoded_text & this_char)
 else
 set the encoded_text to (the encoded_text & encode_char(this_char)) as string
 end if
 end repeat
 return the encoded_text
end encode_text

on encode_char(this_char)
 set the ASCII_num to (the ASCII number this_char)
 set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
 set x to item ((ASCII_num div 16) + 1) of the hex_list
 set y to item ((ASCII_num mod 16) + 1) of the hex_list
 return ("%" & x & y) as string
end encode_char

Oh well, thanks alot Stefan but i might consider just using this in a dialog and drop the app, the script is working as is in script editor, so something is realy broken in the source i have in Xcode… ill have a look on that url ecode stuff, i might learn something, and have someone to look at my project. everything else are working, i got no problems getting infomation for any english movies, so it’s a shame…

The german language has the same problem with the umlauts (äöü) and ß :wink:

heh, my last name is käehne :slight_smile:

this works…

set search1Header to "http://www.imdb.com/find?s=tt&q="
set movie_title to "Grønne slagtere"
set movie_title to Substitute(movie_title)
set search_title to titleIMDB(movie_title)

set top_result to do shell script "curl " & quoted form of (search1Header & search_title) & " | grep -i \"approx matches\""

(*======= SUBROUTINES ============*)
on Substitute(myText)
	script o
		property __s : {"ø", "æ", "å"}
		property __r : {"%BF", "%BE", "%8c"}
		property __t : myText
	end script
	
	set TIDs to AppleScript's text item delimiters
	repeat with i from 1 to count o's __s
		set AppleScript's text item delimiters to o's __s's item i
		set o's __t to o's __t's text items
		set AppleScript's text item delimiters to o's __r's item i
		set o's __t to o's __t as text
	end repeat
	set AppleScript's text item delimiters to TIDs
	
	return o's __t
end Substitute

on titleIMDB(movie_title)
	set text item delimiters to "."
	set search_title to text items of movie_title
	set text item delimiters to space
	set search_title to search_title as Unicode text
	set text item delimiters to "_"
	set search_title to text items of search_title
	set text item delimiters to space
	set search_title to search_title as Unicode text
	set search_title to text items of search_title
	set text item delimiters to "+"
	set search_title to search_title as Unicode text
	set text item delimiters to ""
	return search_title
end titleIMDB

regulus6633 you are great, thanks alot, i’ll give it a go later when i wake up again, need some sleep here, should have checked the forum a bit earlier :O)

Okay, i’m about to go insane :slight_smile:

regulus6633 your script is working great, but only when i use it in script editor,
as soon as i include it in my app, something brakes, and i just can find out what :(((

maby i can get someone to have a quick look on what the hell im doing wrong here…
i dont see what the problem might be…

and dont think pasting 550 lines here would be the best idea :slight_smile:

I’m heading to Copenhagen today so I won’t have time to look at it. If you want you can zip up your project and email it to me but I’m not sure when I can look at it… maybe tomorrow or maybe someone else can take a look.

Thx alot Hank, i’ll send you a zip then… and keep in mind this project is learning process for me, so :slight_smile: the source might not look that great…

The part which is NOT working must be the “on clicked theObject” but not sure at all.