Pregunta

I would like to get the code from an AppleScript file (.scpt) using AppleScript. I tried the obvious:

set the_file to choose file -- Assume the user chooses a .scpt file
read the_file

However, the result I get if I select a script like this (as seen on AppleScript Editor):

enter image description here

is this:

"FasdUAS 1.101.10ˇˇˇˇ
k
lˇ˛ˇ˛;5 By Richard Kulesus, 2009.  Released without license!±     j By Richard Kulesus, 2009.  Released without license!


lˇ˝
ˇ˝ Use this for whatever!
±. Use this for whatever!
lˇ¸ˇ¸OI I seriously despise code authors who copyright tiny bits of obvious code±í I seriously despise code authors who copyright tiny bits of obvious code
lˇ˚ˇ˚PJ like it's some great treasure.  This is small and simple, and if it saves±î like it's some great treasure.  This is small and simple, and if it saves
lˇ˙ˇ˙LF the next guy some time and trouble coding applescript I'll feel good!±å the next guy some time and trouble coding applescript I'll feel good!
lˇ˘ˇ¯ˇ˜ˇ˘ˇ¯ˇ˜ !
 lˇˆ\"#ˇˆ\">8 Quickly change all the hot-corners to do what you want.#±$$p Quickly change all the hot-corners to do what you want.!%&
%lˇı'(ˇı'C= Particularly useful for presentations and full-screen games.(±))z Particularly useful for presentations and full-screen games.&*+

(etc)

and not this:

-- By Richard Kulesus, 2009.  Released without license!
-- Use this for whatever!
-- I seriously despise code authors who copyright tiny bits of obvious code
-- like it's some great treasure.  This is small and simple, and if it saves
-- the next guy some time and trouble coding applescript I'll feel good!
--
-- Quickly change all the hot-corners to do what you want.

(etc)

Is there any workaround to this problem?

¿Fue útil?

Solución

Another way I ran into, though probably no more acceptable, since the osadecompile utility is invoked:

set scriptContent to do shell script "osadecompile " & quoted form of POSIX path of (choose file)

Otros consejos

This seems to do the trick:

tell application "AppleScript Editor"
    set myScript to open (choose file)
    set scriptContent to (text of myScript) as text
    close myScript
    log scriptContent
end tell
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top