首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AppleScript将应用程序赋值给变量

AppleScript将应用程序赋值给变量
EN

Stack Overflow用户
提问于 2012-02-15 20:34:31
回答 1查看 2.7K关注 0票数 1

安装了多个InDesign之后,ScriptEditor试图对脚本应该运行哪个版本很聪明。但是,我希望把我的脚本干涸,这样我只需要在整个脚本中更改一次应用程序名称。

有一个类似的问题( Applescript path to application using variable ),但这并不适用于所有的问题。问题是,为什么这不适用于所有的事情?

预期的工作如下:

代码语言:javascript
复制
tell application "Adobe InDesign CS5.5"
  log name --"Adobe InDesign CS5.5.app" 
  log full name --"Mactastic:Applications:Adobe InDesign CS5.5:Adobe InDesign CS5.5.app:"
end

一个小小的DRYing动作:

代码语言:javascript
复制
set v to "Adobe InDesign CS5.5"
set a to application v
log name of a --"Adobe InDesign CS5.5" 
log full name of a 
--SYNTAX ERROR: Expected end of line, etc. but found property
--"name" is highlighted in the ScriptEditor

下面是另一个按预期工作的示例:

代码语言:javascript
复制
set f to (choose file)
tell application "Adobe InDesign CS5.5"
  open f without showing window
end tell

但是,这不能像以前那样编译:

代码语言:javascript
复制
set f to (choose file)
set v to "Adobe InDesign CS5.5"
set a to application v
tell a
  open f without showing window
end
--SYNTAX ERROR: Expected “given”, “with”, “without”, other parameter name, etc. but found class name.
--"window" is highlighted in the ScriptEditor

我的环境:

10.6.8

  • ScriptEditor 2.3 (118)

  • Applescript 2.1.2

编辑:游戏结束时,我希望将一些InDesign功能抽象到我自己的类中,如下所示:

InDesign.scpt -抽象InDesign功能的类

代码语言:javascript
复制
on new()
    copy me to self
    --do some initializing
    return self
end new

on _version()
    return "Adobe InDesign CS5.5"
end _version

on _application()
    return application _version()
end _application

on _open(path)
    tell _application() to open path without showing window 
end _open

my_script.scpt --使用上面抽象的InDesign.scpt

代码语言:javascript
复制
set InDesign to (load script file ("my:path:to:scripts:" & "Indesign.scpt"))'s new()
InDesign's _open("my:path:to:indd:file.indd")

在AppleScript中,这是一个很好的机会,而ObjectiveC正是我应该考虑做这种事情的地方。但是,某些事情似乎确实起作用,比如“告诉_application()打开路径”,而“告诉_application()打开路径而不显示窗口”。

EN

回答 1

Stack Overflow用户

发布于 2012-02-15 20:43:25

不如:

代码语言:javascript
复制
set theApplication to "Adobe InDesign CS5.5"

using terms from application "Adobe InDesign CS5.5"
    tell application theApplication
        --do your thing here
    end tell
end using terms from

使用术语from用于让脚本编译,否则tell应用程序theApplication块中的任何内容都不会编译,这是indesign特有的。当应用程序(当应用程序是when服务或远程机器)不存在或在编译时无法访问时,使用术语是很常见的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9300891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档