通过运行另一个 applescript 来更改一个 applescript 中的属性?

发布于 2024-11-28 06:59:47 字数 596 浏览 6 评论 0原文

有谁知道如何通过运行另一个苹果脚本来更改一个苹果脚本中的属性? 我知道如何读取存储在单独脚本中的属性,但我不知道如何编辑它们。

例如。 文件 1 包含属性:(以“测试”形式保存到桌面)

property test : 1

文件 2 能够获取此属性的值

global test
set test to (load script (("/Users/knickman/Desktop/test.scpt") as POSIX file))

if test's test is 1 then    
say "yes"   
else    
say "no"    
end if

这有效。但是,如果我尝试从另一个脚本更改文件 1 中的值,方法如下:

global test
set test to (load script (("/Users/knickman/Desktop/test.scpt") as POSIX file))

set test's test to 1

这不起作用。我想做的事情可能吗?我试图用它作为一个简单的数据库。感谢您的帮助

Does anyone know how to change properties in one applescript by running another applescript?
I know how to read properties stored in a separate script but I can't figure out how to edit them.

For example.
File 1 contains the properties: (saved as "test" to the desktop)

property test : 1

File 2 is able to get the value of this property

global test
set test to (load script (("/Users/knickman/Desktop/test.scpt") as POSIX file))

if test's test is 1 then    
say "yes"   
else    
say "no"    
end if

This works. However, if I try to change the value in file 1 from another script with something along the lines of:

global test
set test to (load script (("/Users/knickman/Desktop/test.scpt") as POSIX file))

set test's test to 1

This doesn't work. Is what I am trying to do even possible? I am trying to use this to act as a simple database. Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟月 2024-12-05 06:59:47

使用 load script 加载脚本会创建存储在内存中 test.scpt 文件中的脚本对象的副本。

修改加载脚本的属性只会更改内存中脚本对象的值,不会影响最初加载脚本的脚本文件。但是,您可以使用 存储脚本命令以使更改持久化:

global test
set test to load script (POSIX file "/Users/knickman/Desktop/test.scpt")

if test's test is 1 then
    say "yes"
    set test's test to 0
else
    say "no"
    set test's test to 1
end if

store script test in (POSIX file "/Users/knickman/Desktop/test.scpt") replacing yes

Loading the script with load script creates a copy of the script object stored in the file test.scpt in memory.

Modifying the loaded script's property will only change the value of the script object in memory, it does not have an effect on the script file that the script was originally loaded from. You can however use the store script command to make the changes persistent:

global test
set test to load script (POSIX file "/Users/knickman/Desktop/test.scpt")

if test's test is 1 then
    say "yes"
    set test's test to 0
else
    say "no"
    set test's test to 1
end if

store script test in (POSIX file "/Users/knickman/Desktop/test.scpt") replacing yes
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文