Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rate Thread Display Modes
Old 04-20-2010, 07:46 AM   #1
vagabond
Prospect
 
Join Date: Apr 2010
Posts: 14
Applescript for unlocking files?

I have an external HD that contains lots of locked folders/subfolders/files. The privileges of these are:

User: Read and Write
Staff: Read Only
Everyone: Read Only

I need to do the following:

WhenI copy a single file (or a folder contaning files) onto my desktop, I want to have that folder (and all the files it contains) to automatically unlock themselves.

In other words, I want them to behave like all other files on my desktop, with the above permissions.

Can Applescript or Automator do that?

Many thanks for any hints,
vagabond is offline   Reply With Quote
Old 04-20-2010, 09:17 AM   #2
benwiggy
League Commissioner
 
Join Date: Aug 2006
Location: London
Posts: 5,782
This would seem to relate to your other thread about permissions on the external drive.

Can I ask why the files are locked (rather than using permissions or ACLs)?
Also, why do you copy these items to your Desktop?

Perhaps there is an easier method of working which may eliminate the need for this practice.

Bear in mind that it's advisable not to have lots of files on your Desktop in OS X. Too many files on the Desktop can slow your system down. It's better to have files organised in folders.
benwiggy is online now   Reply With Quote
Old 04-20-2010, 10:11 AM   #3
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
He could simply modify the Folder Action i already provided by adding a few more "do shell script" commands, right below the line which removes ACLs. [e.g., do shell script "/usr/bin/chflags -R nouchg " & itemPath]

Only a small amount of programming (or social) skill required.

Last edited by Hal Itosis; 04-20-2010 at 10:14 AM.
Hal Itosis is offline   Reply With Quote
Old 04-20-2010, 10:55 AM   #4
vagabond
Prospect
 
Join Date: Apr 2010
Posts: 14
Hi, thank you very much for the suggestions. I am completely ignorant about programming, shell scripts etc, and I do not want to get too much involved with this for fear I might screw things up (which has happened on a number of occasions in the past).

Why I need the files to be locked?

The extrenal HDs I use (over 3T of information) contain folders/subfolders/individual items. These are documents that I have to work with every day. What I do is copy a specific document on my desktop, work on it and save it on my desktop. But I always ened to ahve the original doc safe and away - on an external HD.

Adding/modifying stuff on the HD should require a password as an extra precaution. But reading/copying should not.

I tried various things like permissions etc- doesn't work. Someone came and played around with my computer, as a result o which I had to reinstall everything from scratch...

The safest thing I have discovered is to use a small utlity called Locker to lock teh entire HD and all folders/files that are on it. That keeps them safe.

But now, when I have to copy a file or folder on my desktop, I have to manually unlock, which is not much of a problem, but takes up a few seconds - and if I have to do it 50 times a day it does add up.

Any suggestions?

Many tahnks and very best regards,
vagabond is offline   Reply With Quote
Old 04-20-2010, 11:03 AM   #5
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by vagabond
Any suggestions?

Beyond the info in post #3, what "suggestion" could you possibly need?
[it does exactly what you asked for; just try it first and then tell us what you think.]


Edit: oh alright (step-by-step then), here's the tweaked folder action (as per post #3):
Code:

-- begin applescript
on adding folder items to thisFolder after receiving addedItems
	try
		set saveDelims to AppleScript's text item delimiters
		set AppleScript's text item delimiters to " "
		repeat with thisItem in addedItems
			set itemPath to quoted form of POSIX path of thisItem
			do shell script "/usr/bin/chflags -R nouchg " & itemPath
		end repeat
		set AppleScript's text item delimiters to saveDelims
	end try
end adding folder items to
-- end applescript
• use Script Editor to save that .scpt file in the folder /Library/Scripts/Folder Action Scripts

• use Finder to attach that action to the Desktop folder (or whichever folder you like)

Done.

[it's the same principle for attaching a folder action which asadKing taught you.]

Last edited by Hal Itosis; 04-20-2010 at 11:19 AM. Reason: removed chmod line to simplify matters.
Hal Itosis is offline   Reply With Quote
Old 04-20-2010, 01:38 PM   #6
vagabond
Prospect
 
Join Date: Apr 2010
Posts: 14
Ok, I did exactly as you say, butnothing happens.

I created a new folder on my desktop and I attached the folder action. I note that whenever I try to kovean item ionto that folder, it doesn't get moved, but copied.

But it is still locked.



-- begin applescript
on adding folder items to thisFolder after receiving addedItems
try
set saveDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
repeat with thisItem in addedItems
set itemPath to quoted form of POSIX path of thisItem
do shell script "/usr/bin/chflags -R nouchg " & itemPath
end repeat
set AppleScript's text item delimiters to saveDelims
end try
end adding folder items to
-- end applescript
vagabond is offline   Reply With Quote
Old 04-21-2010, 12:31 AM   #7
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by vagabond
Ok, I did exactly as you say, butnothing happens.

I created a new folder on my desktop and I attached the folder action. I note that whenever I try to kovean item ionto that folder, it doesn't get moved, but copied.

But it is still locked.

Works perfect on my Mac.

But, perhaps there is more than basic "locking" going on here...

Quote:
Originally Posted by vagabond
The safest thing I have discovered is to use a small utlity called Locker to lock teh entire HD and all folders/files that are on it. That keeps them safe.

Wouldn't it be funny if "Locker" is using ACLs?

So, what exactly does "Locker" do to a file... can you tell us?
[i'll bet it's probably removing write access as well as adding the uchg flag]

---> Show us a listing of some file on which "Locker" has worked its magic:

ls -alOe /path/to/a/"locked"/file

Once we can see what "Locker" *actually* does, then we can undo it.

--

EDIT: FWIW, i just located "Locker" and tested it. All it does is add a uchg flag. Needless to say, my folder action worked just fine and unlocked an entire folder's worth of stuff locked by Locker. Therefore . . . that means the bug (or whatever) is on your end.

So do this: use that blue command to list the item(s) that were dragged onto the desktop which you allege my Folder Action failed to unlock. What may be happening is a lack of adequate user or group access (or something other than a uchg flag).

Last edited by Hal Itosis; 04-21-2010 at 01:09 AM.
Hal Itosis is offline   Reply With Quote
Old 04-21-2010, 02:48 AM   #8
vagabond
Prospect
 
Join Date: Apr 2010
Posts: 14
Locker function

This is it.
Attached Files
File Type: zip locker.dmg.zip (55.6 KB, 149 views)
vagabond is offline   Reply With Quote
Old 04-21-2010, 03:27 AM   #9
vagabond
Prospect
 
Join Date: Apr 2010
Posts: 14
Excuse my ignorance, but how do I do that?





Quote:
Originally Posted by Hal Itosis
Works perfect on my Mac.

But, perhaps there is more than basic "locking" going on here...


Wouldn't it be funny if "Locker" is using ACLs?

So, what exactly does "Locker" do to a file... can you tell us?
[i'll bet it's probably removing write access as well as adding the uchg flag]

---> Show us a listing of some file on which "Locker" has worked its magic:

ls -alOe /path/to/a/"locked"/file

Once we can see what "Locker" *actually* does, then we can undo it.

--

EDIT: FWIW, i just located "Locker" and tested it. All it does is add a uchg flag. Needless to say, my folder action worked just fine and unlocked an entire folder's worth of stuff locked by Locker. Therefore . . . that means the bug (or whatever) is on your end.

So do this: use that blue command to list the item(s) that were dragged onto the desktop which you allege my Folder Action failed to unlock. What may be happening is a lack of adequate user or group access (or something other than a uchg flag).

vagabond is offline   Reply With Quote
Old 04-21-2010, 02:04 PM   #10
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by vagabond
Excuse my ignorance, but how do I do that?

I guess you meant this part (?): ls -alOe /path/to/a/"locked"/file

Launch the Terminal.app program (one way: activate Spotlight with command-space, type term and pause a second... chances are Terminal will be the item selected, so hit return).

Copy/paste

ls -alOe

...and leave a **space** at the end (after the 'e').

Select something on the desktop (a folder or file) which you claim the Folder Action failed to unlock and drag it into the Terminal window (or use copy/paste again). The proper pathname of the item should appear after ls -alOe looking *something* like:

ls -alOe /Users/vagabond/Desktop/foo

So just hit enter (or return). Finally, copy /paste all that text back here so folks can read it.
Hal Itosis is offline   Reply With Quote
Old 04-21-2010, 03:45 PM   #11
vagabond
Prospect
 
Join Date: Apr 2010
Posts: 14
Thanks.

There we go:

total 173576
drwxr-xr-x 20 anthonyg staff uchg 680 11 Apr 13:31 .
drwxr-xr-x 4 anthonyg staff - 136 21 Apr 23:39 ..
-rwxr--r--@ 1 anthonyg staff - 5003440 11 Apr 10:38 scan3770.jpg
-rwxr--r--@ 1 anthonyg staff - 4912934 11 Apr 10:39 scan3771.jpg
-rwxr--r--@ 1 anthonyg staff - 4855317 11 Apr 10:40 scan3772.jpg
-rwxr--r--@ 1 anthonyg staff - 4530335 11 Apr 10:41 scan3773.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5304059 11 Apr 13:22 scan3774.jpg
-rwxr--r--@ 1 anthonyg staff uchg 3366926 11 Apr 10:44 scan3775.jpg
-rwxr--r--@ 1 anthonyg staff uchg 4368651 11 Apr 10:45 scan3776.jpg
-rwxr--r--@ 1 anthonyg staff uchg 4552605 11 Apr 10:46 scan3777.jpg
-rwxr--r--@ 1 anthonyg staff uchg 4883757 11 Apr 10:47 scan3778.jpg
-rwxr--r--@ 1 anthonyg staff uchg 4974222 11 Apr 10:49 scan3779.jpg
-rwxr--r--@ 1 anthonyg staff uchg 4850674 11 Apr 13:22 scan3780.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5266049 11 Apr 13:22 scan3781.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5340507 11 Apr 13:22 scan3782.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5257997 11 Apr 13:21 scan3783.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5661010 11 Apr 10:56 scan3784.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5071824 11 Apr 13:21 scan3785.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5096860 11 Apr 13:21 scan3786.jpg
-rwxr--r--@ 1 anthonyg staff uchg 5106310 11 Apr 13:21 scan3787.jpg
anthony-georgieffs-power-mac-g5:~ anthonyg$


This was a folder located on an external HD that I had locked with the Locker app. This folder contains individual items.

I note that some of the individual items got unlocked, vbut some didn't.

Also, I note that whenever I attach your script to my Desktop, sometimes it styas here, smetimes it egts removed without any reason whatsoever. So I cannot be sure whether it is there or not.

Many thanks and best regs,
vagabond is offline   Reply With Quote
Old 04-21-2010, 04:52 PM   #12
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by vagabond
This was a folder located on an external HD that I had locked with the Locker app. This folder contains individual items.

I note that some of the individual items got unlocked, vbut some didn't.

So i see. That's pretty odd, since I see absolutely no reason for that to happen. There is no apparent difference between the ones that did unlock and the ones that didn't.


Quote:
Originally Posted by vagabond
Also, I note that whenever I attach your script to my Desktop, sometimes it styas here, smetimes it egts removed without any reason whatsoever. So I cannot be sure whether it is there or not.

That too is strange. I can only guess your Mac's disk directory structure may have some underlying problem, or something of that nature.

You should use Disk Utility to check that... either by booting off the system DVD or (a faster way) booting into single-user mode and running

fsck -fy

See http://support.apple.com/kb/TS1417 for more detail.
If that turns up with no error, I'm not sure what to say.

Last edited by Hal Itosis; 04-21-2010 at 04:55 PM.
Hal Itosis is offline   Reply With Quote
Reply

Tags
applescript, batch, folders, permissions, unlock

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:51 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.