Here’s my problem. My application runs fine on a G5 computer that I build it on. When I run the application on a G4 powerbook it works fine but doesn’t save a file that I write settings to. And just the opposite happens… if I build the project on the powerbook, everything works properly there. But if I move the application built on the G4 to the G5 the application runs fine but again doesn’t save the file.
So bottom line: the application runs perfectly on both computers but the settings file is only saved on the computer I build the project on.
my build settings seem to be fine…
I’m building my project on a G5 mac. It’s set to build as a universal binary and is set to release build mode. Looking at the build configuration the architecture is set to “ppc i386”. I have zerolink unchecked too. I do a “clean all” before I build the project and I’ve even manually deleted the build folder before building the project.
The file is set to write when the application quits and is located here in my applescript…
on will quit theObject
writeTo(setsData, prefsFilePath, false, list)
end will quit
Here’s how I have my write path defined…
property prefFolderLocation : path to preferences folder from user domain as Unicode text
property prefFileName : “com.test.testapp”
property prefsFilePath : prefFolderLocation & prefFileName
I checked the setsData variable to make sure it had data inside of it so that the write would happen properly. Plus the write does happen with no problem, but only on the machine I build the project on.
and here’s the write handler…
on writeTo(this_data, target_file, append_data, mode)
try
set target_file to target_file as Unicode text
if target_file does not contain ":" then set target_file to POSIX file target_file as Unicode text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof as mode
close access the open_target_file
return true
on error errorText number errorNumber
log "Error writing apps file."
log " Error " & errorNumber & ": " & errorText
try
close access file target_file
end try
return false
end try
end writeTo
Yes, and I do use them for every other setting in my app, just not this particular setsData list. It’s a very complicated list of lists (with records inside the lists too) and it can get big, so I didn’t want to use it. I didn’t even know how to use it for something this complicated actually. I knew how to use the write handler for setsData because it was a plain applescript first so I had it working there.
But you’re right about one thing, the user-defaults written settings are written properly and works on both machines no matter which computer built the application. There must be something wrong about the writing of setsData but I can’t figure it out. I’m still trying though.
I just figured out the problem but don’t know how to fix it, maybe someone does??? I hope!
This statement is turning into a literal path and since the root hard drive name is different on both computers there’s an error when it the computer that didn’t compile the script tries to find the preferences folder…
property prefFolderLocation : path to preferences folder as Unicode text
In other words that statement is being written in the code as…
hard drive name of the compter that built the application:Users:username:Library:Preferences
It doesn’t seem right but can anybody give me a fix for this?
-- Example of a folder named "Drop/Box"
"MBP HD:Users:bruce:Public:Drop/Box:" -- HFS path
"/Users/bruce/Public/Drop:Box/" -- POSIX path
Alternatively:
on writeTo()
try
if class of target_file is not in {alias, file} then set target_file to POSIX file (POSIX path of target_file)
set open_target_file to open for access target_file with write permission
--
end try
end writeTo
I can’t set those path’s as a property. I have to use “set” to set them instead. Here’s how I did it for others to see. I had to do it in one of the handlers that gets called when the application first runs.
on will finish launching theObject
set prefFolderLocation to path to preferences folder from user domain as Unicode text
set prefFileName to “com.test.testapp”
set prefsFilePath to prefFolderLocation & prefFileName
end will finish launching
Then I also had to set those variables as global variables at the top of the script. Now evrything works as it should. It seems crazy but I’m sure it makes sense on some level.