When is a property defined?

I tried to copy one of my apps to another computer, and found that it didn’t work. In the app, I had a property called pathToRoot that was defined in the property declaration as “POSIX path of ((path to Documents as string) & “weather.plist”” What I fond out was that pathToRoot was defined on the other computer with the same path as the computer I wrote the app on, instead of its own path to its own documents folder. This could be fixed by declaring pathToRoot as missing value, and then setting its value in the applicationWillFinishLaunching method. Why is this so? Is this a problem of when properties are defined?

Ric

Yep – properties have whatever value they had when the compiled script was last saved. For ASObjC apps, that effectively means what they had when the app was built.

Anyway there is a hard rule in AppleScript for portability:

Never define relative paths in a property

Well, it may be a hard rule, but it’s one I never heard of. It’s one I’ll certainly keep in mind from here on out.

Ric

I found this thread in trying to figure out a way to define part of a path that changes every few months. From reading this thread, this might be a bad idea, but I would like to do the following if possible.

I have several scripts that need updating regularly and they open 7 windows that have only one folder that changes. Rather than change each of them manually is there a way to do something like what I have below?

property newFolder : "July"

tell application "Finder"
	close every window
	make new Finder window
	make new Finder window
	
	set bounds of Finder window 1 to {0, 44, 1920, 416}
	set bounds of Finder window 2 to {0, 438, 1920, 810}
	set target of Finder window 1 to alias "Media 1TB:My Files:Documents:"newFolder":Research Paper:"
	set target of Finder window 2 to alias "Media 1TB:My Files:Documents:"newFolder":Documents to Read:How to AppleScript.pdf"
	
end tell

do you mean this


property newFolder : "July"

set newFolder to month of (current date) as text -- sets the property to the current month

tell application "Finder"
	close every window
	make new Finder window
	make new Finder window
	
	set bounds of Finder window 1 to {0, 44, 1920, 416}
	set bounds of Finder window 2 to {0, 438, 1920, 810}
	set target of Finder window 1 to alias "Media 1TB:My Files:Documents:" & newFolder & ":Research Paper:"
	set target of Finder window 2 to alias "Media 1TB:My Files:Documents:" & newFolder & ":Documents to Read:How to AppleScript.pdf"
	
end tell


Yes, that is what I am looking for, seems like it should work but for some reason it gives me an error.

property newFolder : "Applications"

tell application "Finder"
	close every window
	make new Finder window
	
	set bounds of Finder window 1 to {0, 44, 1920, 416}
	set target of Finder window 1 to alias "Macintosh HD:" & newFolder & ":Utilities:"
	
end tell

Browser: Safari 531.21.10
Operating System: Mac OS X (10.7)

I am not sure why it error on alias but it works ok when you take that out. Do you see any problem in running this script or should this be done a better way?

This works

Open this Scriplet in your Editor:
property newFolder : "Applications"

tell application "Finder"
   close every window
   make new Finder window
   
   set bounds of Finder window 1 to {0, 44, 1920, 416}
   set target of Finder window 1 to "Macintosh HD:" & newFolder & ":Utilities:"
   
end tell