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

使用AppleScript从AppleScript文件(.scpt)读取代码,applescript,readfile,Applescript,Readfile,我想使用AppleScript从AppleScript文件(.scpt)获取代码。我尝试了显而易见的方法: set the_file to choose file -- Assume the user chooses a .scpt file read the_file 但是,如果我选择这样一个脚本(如AppleScript Editor上所示),则会得到以下结果: 这是: "FasdUAS 1.101.10ˇˇˇˇ k lˇ˛ˇ˛ ;5 By Richard Kulesus, 2009

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

set the_file to choose file -- Assume the user chooses a .scpt file
read the_file
但是,如果我选择这样一个脚本(如AppleScript Editor上所示),则会得到以下结果:

这是:

"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.
(等)


这个问题有解决办法吗?

这似乎可以解决问题:

tell application "AppleScript Editor" set myScript to open (choose file) set scriptContent to (text of myScript) as text close myScript log scriptContent end tell 告诉应用程序“AppleScript编辑器” 将myScript设置为打开(选择文件) 将scriptContent设置为(myScript的文本)作为文本 关闭myScript 日志脚本内容 结束语
这似乎起到了作用:

tell application "AppleScript Editor" set myScript to open (choose file) set scriptContent to (text of myScript) as text close myScript log scriptContent end tell 告诉应用程序“AppleScript编辑器” 将myScript设置为打开(选择文件) 将scriptContent设置为(myScript的文本)作为文本 关闭myScript 日志脚本内容 结束语
我遇到的另一种方法,尽管可能不再被接受,因为调用了
osadecompile
实用程序:

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

我遇到的另一种方法,尽管可能不再被接受,因为调用了
osadecompile
实用程序:

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

是的,我知道这样做会奏效,但我宁愿不打开任何应用程序。@Alex-
将myScript设置为加载脚本(选择文件)
看起来很有希望-脚本编辑器在“回复”选项卡中显示加载的脚本,但到目前为止我还没有弄清楚如何将此文本转换为变量。是的,我知道这样做会奏效,但我宁愿不打开任何应用程序。@Alex-
将myScript设置为加载脚本(选择文件)
看起来很有希望-脚本编辑器在“回复”选项卡中显示加载的脚本,但到目前为止,我还不知道如何将此文本转换为变量。