Hi,
I’d like to make a script that can create a webloc file from a .txt file that contains only an url.
Is that possible, I don’t really know where to start from.
Thanks.
Hi CCharless,
Try this:
set the_url to "http://macscripter.net"
tell application "Finder"
make new internet location file at desktop to the_url with properties {name:"test"}
end tell
What’s interesting to me is that the created file is a plist file.
gl,
Thank you kel1,
It works, but now how do I make the script use an url that is written in a txt file ?
It’s actually a txt file that contains only an url.
Actually here is the whole thing :
I have a folder containing other folders. Each of these other folders contain one txt file named xxxx.txt and containing an url. What I’d like to do is make a folder script that transforms each .txt file into a .webloc file.
Also I would like that each time I place a new folder in the main folder it does that same thing again.
I hope I am clear.
Thanks for your help.
Hi CCharless,
Firstly, I’d start with using Folder Actions. Then, I’d read the files. Next, make the internet location files (think about how to name them also). Etc.
It’s an interesting lesson.
gl,
Hello.
You should find some code for making a webloc in the Code Exchange section, made within the last few months.
Thank you both for your answers.
Looking at kel1’s result .webloc file, I realized that adding a few lines before and after the url that is in my file could “transform” it in a “working” .webloc file.
I’ve managed to have the “webloc” extension instead of “txt” by an other mean so I just need to add those portions of text to make this work.
The problem I couldn’t solve, and I swear I’ve searched a lot, is to make the script adding characters at the beginning of the file instead of replacing characters.
Here is my actual script :
set the_file to "xxx.webloc"
open for access the_file with write permission
write "<dict>
<key>URL</key>
<string>" to the_file
write "</string>
</dict>" to the_file starting at eof
close access the_file
Hello.
This should work as long as the filesize is greater than zero.
set mf to (do shell script " ls -1 ~/Desktop/test.txt")
set mf to POSIX file mf as alias as text
set fref to open for access mf with write permission
set oldText to read fref from 1
set eof fref to 0
write "this is at the start " to fref
write oldText to fref
close access fref
Reading up on catching error, and the Unscripted tutorial on File Handling are left as exercises for you.
Corrected!
Thank you McUsrII,
The only problem is that the first character is rewritten at the beginning of the file.
There must be a little mistake in your script but I can’t find it.
I tried changing the two 1 to two 0 or only the first one or only the second one but it doesn’t work either.
I’m so sorry about that.
Change the last place with eof to
set eof fref to 0
and you should be good to go.
Oups, I thought I had tested that and it didn’t work, I must have done something wrong 'cause it’s actually working indeed. Thanks again.
I’ll now try the next step : automatically applying that Script to every .webloc file included in every sub-folder of a specific folder. Being a total n00b, it’s not gonna be easy and I’ll probably have to come back later for more help.
I’ll keep you posted anyway.
And thanks again to both of you.