Problem with scripting addition and ASObj-C

I am not sure if the behavior I’ve been seeing with a script is a bug, known problem or if I’m doing something stupid. The script shown at the end of this post works with "use framework “Foundation” " commented out. If I uncomment the line I get an error that displays the message, “An error of type -1409 has occurred.” -1409 is the error errFSForkNotFound which means the named fork doesn’t exists. This doesn’t make a lot of sense.

This runs the same way in SD and Script Editor. I am wondering if there is a way to to leave in the use framework “Foundation” line and still be able to use the “write” scripting addition. I know I can use ASObj-C to write the file but I am trying to minimize the ASObj-C. This is part of a script that gets weather info from the weather sensor in my back yard and is like to be updated and used a lot. ASObj-C is harder to work with when developing a solution in that I can’t run it in SD and switching editors makes it a lot harder. So far I only used ASObj-C 3 times to download the weather data to my Mac and it is not crashing a lot with just that while using SD for developing the script.

I am guessing when "use framework “Foundation” " is used something is compiled and/or run differently in Script Debugger.


use scripting additions

-- use framework "Foundation"

set PathToFolder to "Bills second iMac HD:Users:bill:Desktop:Test:"

set WeatherDataFileName to "TestFile.txt"

set TheText to "Test"

tell application "Finder" to make new file at PathToFolder with properties {name:WeatherDataFileName}

set TheText to "Test"

write TheText to file (PathToFolder & WeatherDataFileName)

Bill Kopp

Is there a reason you’re using finder to make the file instead of “open for access”? I’m sure that’s where the issue is. Finder is probably not returning a path in the form you want.

The script below keeps the Use Framework and uses scripting additions and works just fine here. (You’d need to retool the path to stuff for your files)


use framework "Foundation"

use scripting additions

set PathToFolder to path to desktop folder as text

set WeatherDataFileName to "TestFile.txt"

set TheText to "Test"

set myFile to (PathToFolder & WeatherDataFileName)

try

set openFile to open for access file myFile with write permission

on error

close access file myFile

set openFile to open for access file myFile with write permission

end try

write TheText to openFile

close access openFile

I was too lazy to use “open for access” since I just wanted to do a straight write. However as your response points out my laziness caused me a lot more work.

Thank you for your response. It didn’t occur to me that just because the “write” command failed that doesn’t mean open and close access would not work.

Your help is much appreciated :grinning::grinning::grinning:

Bill

1 Like

You’re running into the issue described here:

It’s to do with how file specifiers are resolved. Best to use:

write TheText to ((PathToFolder & WeatherDataFileName) as «class furl»)