tknickman
tknickman

Reputation: 4631

Change properties in one applescript by running another applescript?

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

Upvotes: 3

Views: 712

Answers (1)

sakra
sakra

Reputation: 65931

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

Upvotes: 3

Related Questions