使用AppleScript从AppleScript文件中读取代码(.scpt)

时间:2014-02-24 17:46:01

标签: applescript readfile

我想使用AppleScript从AppleScript文件(.scpt)获取代码。我尝试了显而易见的事实:

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

但是,如果我选择这样的脚本(如AppleScript编辑器中所示),我得到的结果是:

enter image description here

就是这样:

"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.&*+

(等)

而不是这个:

-- 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.

(等)

这个问题有解决办法吗?

2 个答案:

答案 0 :(得分:3)

我遇到的另一种方式,虽然可能不再可接受,因为调用了osadecompile实用程序:

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

答案 1 :(得分:0)

这似乎可以解决问题:

tell application "AppleScript Editor"
    set myScript to open (choose file)
    set scriptContent to (text of myScript) as text
    close myScript
    log scriptContent
end tell