I thought it a nice idea to reverse engineer the “Open this Scriplet in your Editor:” from this forum for my own blog. Then I had the idea to do this in AppleScript. I found a nice method to do the urlencoding. But how do I read a script file?
The below script reads the script file as text:
set theFile to choose file with prompt "Please select a script file"
set theFile to theFile as string
return read file theFile
There isn’t any error handling, yet, and I need to restrict the file dialog to scpt files.
You’ll want load script for a script(scpt or scptd extension). It’s in Standard Additions, in the Scripting Commands suite.
If it’s text (applescript extension) you use read file. What you do next depends on what your goal is.
set pathToSource to (choose file with prompt "Please select a script file") as text
set textCode to do shell script "/usr/bin/osadecompile " & quoted form of POSIX path of pathToSource