I think I’m missing something obvious. Why does this work with a directory as the path but not a file? I get “Connection is invalid” or nul within Xcode. Any insight would be helpful. Thanks.
script runScript
-- get dir path to check
set thePath to current application's NSApp's passedValue() as text
-- set file manager to default
set theFileManager to current application's NSFileManager's defaultManager()
-- get attributes of path
set theAttributes to theFileManager's attributesOfItemAtPath_error_(thePath, missing value)
-- return attribs
return theAttributes
end script
tell application "ASObjC Runner" to set theResult to run the script {runScript} passing "/etc/hosts" with result returned
log theResult
How are you passing the name of the file? Are you including the extension in the path? I get null if I pass a file without an extension, whereas you obviously don’t need one for a folder.
Well, assuming that bogus.txt is an actual file, that would work fine in ASOC. I don’t have ASObjC Runner so I’m guessing that the problem is with it. What happens if you log thePath? Does it look right?
It’s not unusual for me to screw up a path, but in this case I am absolutely sure. To be sure, I even used “/etc/hosts” because I know it exists for sure and its path is short and sweet. I can get the attributes of “/etc” but not “/etc/hosts”. For the life of me I can’t figure out why.
script runScript
-- get dir path to check
set thePath to current application's NSApp's passedValue() as text
-- set file manager to default
set theFileManager to current application's NSFileManager's defaultManager()
-- get attributes of path
set theAttributes to theFileManager's attributesOfItemAtPath_error_(thePath, missing value)
-- return attribs
return theAttributes
end script
tell application "ASObjC Runner" to set theResult to run the script {runScript} passing "/etc/hosts" with result returned
log theResult
This thread raises an interesting issue. My first reaction was to try with a bad path and check the NSError, like this:
script runScript
-- get dir path to check
set thePath to current application's NSApp's passedValue() as text
-- set file manager to default
set theFileManager to current application's NSFileManager's defaultManager()
-- get attributes of path
set {theAttributes, theError} to theFileManager's attributesOfItemAtPath_error_(thePath, reference)
-- return attribs
return {theAttributes, theError}
end script
tell application "ASObjC Runner" to set theResult to run the script {runScript} passing "/blah/blah" with result returned
log theResult
The problem, though, is that ASObjC Runner only returns AS classes, so the NSError is dropped. Both items come through as references to ASObjC Runner, which is what happens to nulls in a list.
Anyway, I’ve just uploaded a new version, 1.0.8. If it detects an NSError in the result, it will replace it with a string containing the error’s localizedDescription. So if you update to the latest version and run the code above, you should see what the error is.
Okay I’m home now and I’m using a different machine and it works fine.
Is it a limitation of 10.6.8 (my work machine) vs 10.7.2 (my home machine) with ASObjC_Runner? I will download your latest version on my work machine tomorrow and see if yields different results. Nothing seems to make it work on the 10.6.8 machine.
I appreciate all your help. I don’t want to be difficult and have you chase down a problem that is specific to my machine. I’m just glad to know it works in Xcode, regardless of my results with ASObjC_Runner. I’m a big fan of your utility since it allows me to build out a library of code that I can then use in larger projects without having to create individual projects within Xcode.
So there was a problem with 10.6 – I’d added a framework (AVFoundation) that is Lion only. Version 1.0.9 fixes the problem. Thanks for bringing it to my attention.