Setting url of browser widget, incompatible characters

Tore Nilsen tore.nilsen at me.com
Wed Mar 23 08:11:27 EDT 2016


I have been working with the browser widget this morning, trying to use it to show/play media files, and I have come across some oddities with some characters  in file names being incompatible with the widget. The script I originally used use is as follows:

on mouseUp

answer file "Choose file"

put "file://"& it into tPath

put tPath into field "url"

set url of widget "browser" to tPath

end mouseUp


This would work unless the file name contained space characters. Changing the script to replace space characters with %20 would rectify this problem. 

on mouseUp

answer file "Choose file"

put "file://"& it into tPath

repeat with i = 1 to the number of chars of tPath

if char i of tPath is space then

put "%20" into char i of tPath

end if

end repeat

put tPath into field "url"

set url of widget "browser" to tPath

end mouseUp


However, in some instances, a space character between two words would not be recognised as such. I tried to delete only the original space character in Finder, and add it again, but it would still not be recognised. Only when I wrote the file name from scratch, space characters and all, would the space character be recognised and the url would be set. 

Here are some urls that do not work:
file:///Users/torenilsen/Documents/MultimedieLab/Musikk/01%20My%20My,%20Hey%20Hey%20(Out%20of%20the Blue).m4p

file:///Users/torenilsen/Documents/MultimedieLab/Musikk/05%20The%20Piano%20Has%20Been%20Drinking%20(Not Me).m4a

file:///Users/torenilsen/Documents/MultimedieLab/Musikk/07%20Hearts%20and%20Bones%20(Live%20In%20New%20York 2011).m4p

file:///Users/torenilsen/Documents/MultimedieLab/Musikk/12%20Blues%20Can't%20Even%20Find Me.m4a


As one can see, the last space character is not replaced. All of these examples contains either apostrophes or parenthesises. Removing these characters from the file name does not help either. In order to have these urls working, the file name has to be retyped in Finder. Have anyone else come across this. I am using LC 8 dp 16 and OS X 10.11.4 (beta).

Regard
Tore Nilsen


More information about the use-livecode mailing list