Unclicking the Locked button

I feel like I am almost there on this one.

In my script I am making sure the user has not clicked the Locked checkbox on the file in the Finder. In my old script I used the Finder to set the locked attribute to unchecked.

In ASOC, from what I have read it looks like I need something like this:

set this_item to current application's NSString's stringWithString_("/Users/mktcyx/Desktop/Test.txt")

set isSetUnLocked to fileManager's setAttributes_ofItemAtPath_error_(NSFileImmutable = 0, this_item, missing value)

The problem is that first value I am passing. It says it as an object of class NSDictionary. I am not sure how to create an NSDictionary object that indicates I want NSFileImmutable to be set to 0 or 1.

Essentially, I am trying with the NSFileManager class to do this shell script:

set this_item to current application's NSString's stringWithString_("/Users/mktcyx/Desktop/Test.txt")

do shell script ("chflags nouchg " & this_item)

I could always just use the shell script but I am trying to learn so I want to make it work. Any advice?

Model: iMac
Browser: Firefox 3.6.4
Operating System: Mac OS X (10.6)

Here’s how you’d do it in ObjC:

NSDictionary *theDict = [NSDictionary dictionaryWithObjects:[[NSNumber numberWithInt:0] forKeys:@“NSFileImmutable”];

So in ASOC I think it would be:
set theDict to NSDictionary’s alloc()'s dictionaryWithObjects_forKeys_(NSNumber’s alloc()'s numberWithInt_(0), “NSFileImmutable”)

Not tested but just a guess. Might not need the alloc since those are class methods for NSDict and NSNumber. And you’ll have to declare the classes or use the “current applications…” form

Thanks. That got me to the point where I could finish it. That method was looking for two NSArrays as input. And it looks like it is fine accepting a 0 without involving NSNumber.

set theDict to current application's NSDictionary's dictionaryWithObjects_forKeys_({0}, {"NSFileImmutable"}) --0=Unlocked, 1=Locked
set isSetUnLocked to fileManager's setAttributes_ofItemAtPath_error_(theDict, this_item, missing value)

Thanks again.

Model: iMac
Browser: Firefox 3.6.4
Operating System: Mac OS X (10.6)

You can just pass a record where a dictionary is required – in this case, something like {NSFileImmutable:0}.

The way Shane said is the easiest, but if you’re using NSDictionary methods and you’re only adding one key/value pair then use the singular method dictionaryWithObject:forKey rather than the plural dictionaryWithObjects:forKeys:

Ric