Friday, December 19, 2014

#1 2012-05-11 06:44:40 am

flex20
Member
From: Sydney, Australia
Registered: 2010-08-24
Posts: 163

Folder action script to hide all files ending with "plist.lockfile"

Hi,
I'm searching without much luck for a folder action script to attach to the Preferences folders in /Library and ~/Library to hide all existing and new files with the name ending in "plist.lockfile".  Can anybody help me please?

Offline

 

#2 2012-05-11 09:11:24 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Folder action script to hide all files ending with "plist.lockfile"

Hello

As these prefs files are not modified frequently, I wrote a standard script.

You may edit it as a Folder Action Script if you really need that.

Applescript:


my hidePlistLockfile(path to preferences from user domain as text)
my hidePlistLockfile(path to preferences from local domain as text)

on hidePlistLockfile(leDossier)
   tell application "System Events"
       tell folder leDossier
           set prefs to every file whose name ends with ".plist.lockfile"
           repeat with aFile in prefs
               set visible of aFile to false
           end repeat
       end tell
   end tell
end hidePlistLockfile

Yvan KOENIG (VALLAURIS, France) vendredi 11 mai 2012 16:11:14

Offline

 

#3 2012-05-11 11:07:29 am

flex20
Member
From: Sydney, Australia
Registered: 2010-08-24
Posts: 163

Re: Folder action script to hide all files ending with "plist.lockfile"

Hi Yvan,
Many thanks. Your script works very well but only for the plist.lockfile files with normal permissions.  It doesn't work for the files with system (root) permissions.  These in my case are 6 out of 224 in the user domain and all 14 in the local domain.
Could you modify the script to take care of them as well?  I'd be happy to enter the admin password when I run the script.

Offline

 

#4 2012-05-12 03:36:15 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Folder action script to hide all files ending with "plist.lockfile"

Hello

I apologizes.

I know the syntax required to set the visibility bit but I don't know the one setting administrator privileges when triggering System Events.

I know the way to work with administrator privileges when triggering a Shell script but I don't know the way to rule the visibility in such case.

I don't know the way to rule visibility from the Finder.

If you installed the developper tools on your machine, you may use :

Applescript:


my hidePlistLockfile(path to preferences from user domain as text)
my hidePlistLockfile(path to preferences from local domain as text)

on hidePlistLockfile(leDossier)
   tell application "System Events"
       tell folder leDossier
           set prefs to every file whose name ends with ".plist.lockfile"
           repeat with aFile in prefs
               my hideAfile(path of aFile)
           end repeat
       end tell
   end tell
end hidePlistLockfile

on hideAfile(thePath)
   quoted form of POSIX path of thePath
   do shell script "/Developer/usr/bin/SetFile -a V " & result with administrator privileges
end hideAfile

Yvan KOENIG (VALLAURIS, France) samedi 12 mai 2012 10:35:14

Last edited by Yvan Koenig (2012-05-12 05:07:49 am)

Offline

 

#5 2012-05-12 11:36:28 am

flex20
Member
From: Sydney, Australia
Registered: 2010-08-24
Posts: 163

Re: Folder action script to hide all files ending with "plist.lockfile"

Hi Yvan,
Many thanks again.  Your new version works perfectly.  The only small change is for the people who don't have the old stile /Developer folder but the new stand-alone Xcode app in /Applications.  The the path to the SetFile is then
/Applications/Xcode.app/Contents/Developer/usr/bin/SetFile

You mentioned the option of using a Shell script instead.  That triggered my memory of an older Shell script I had dealing with some visibility issues.  I found it and after searching MacScripter for permissions issues, I wrote this script:

Applescript:


-- Hide or Unhide plist.lockfile files -- version 2.0

display dialog "Hide or Unhide the plist.lockfile files in the Preferences folders in /Library and ~/Library." & return & return & "Will require to enter an administrator password." & return with title "Hide or Unhide the plist.lockfile files" buttons {"Cancel", "Hide", "Unhide"} default button 1 giving up after 60

set dialogResult to result
set giveUp to gave up of dialogResult
if giveUp is true then error number -128 -- Cancel on giving up to cancel the script.
set user_choice to button returned of dialogResult -- Set the user choice.

-- Process the user choice. Will require to enter an admin password.
if user_choice is "Hide" then
   do shell script "chflags hidden /Library/Preferences/*.plist.lockfile" with administrator privileges
   do shell script "chflags hidden ~/Library/Preferences/*.plist.lockfile" with administrator privileges
else if user_choice is "Unhide" then
   do shell script "chflags nohidden /Library/Preferences/*.plist.lockfile" with administrator privileges
   do shell script "chflags nohidden ~/Library/Preferences/*.plist.lockfile" with administrator privileges
end if

Using only the Shell script for processing, makes the script running much faster than using System Events.  I also included the option to either hide or unhide the plist.lockfile files.  I agree that there isn't any point in making it a folder action script.  I found it convenient to save the script as an application "Hide Unhide plist.lockfile.app".

Thank you again for your help.

Last edited by flex20 (2012-05-13 10:19:57 am)

Offline

 

#6 2012-05-12 03:04:23 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Folder action script to hide all files ending with "plist.lockfile"

I tested ChFlags.
Alas, it's a PPC only code so it can't be used under Lion.

Yvan KOENIG (VALLAURIS, France) samedi 12 mai 2012 22:04:15

Offline

 

#7 2012-05-12 05:04:45 pm

flex20
Member
From: Sydney, Australia
Registered: 2010-08-24
Posts: 163

Re: Folder action script to hide all files ending with "plist.lockfile"

Hi Yvan,

I'm not sure we are talking about the same "chflags".  It works perfectly on my late 2009 iMac with OS X Lion 10.7.4 and on my daughter's MBA with Lion 10.7.3.  Did you try to run the script on your Mac with Lion and it didn't work?

Also, before installing Lion on my iMac last August, I deleted all PPC apps and utilities of any kind.  I checked again now in System Information and there are no PPC apps on my Mac.  My understanding is that "chflags" is a standard UNIX command updated as needed in every OS X release so, in Lion it couldn't be PPC.  It does work here.

Let me know if the script works for you.

Offline

 

#8 2012-05-13 03:15:04 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Folder action script to hide all files ending with "plist.lockfile"

Hello

Here the instructions
    quoted form of POSIX path of thePath
    do shell script "chflags hidden " & result with administrator privileges

failed on 2012/05/11 when I was running 10.7.3 and behave flawlessly today under 10.7.4.

On the backup of my 10.7.3 system made before installing 10.7.4, chflags is dated 2011/11/2 last mod : 2012/02/02

On the system 10.7.4 chflags is dated 2012/02/22 last mod 2012/05/11

The two files have the same size and when I compare them with HexEdit, I got no difference.

So, I must assume that something was fooling the system. Alas I don't guess what.
Maybe it was just that the returned message was not relevant.
In the log report, I got only « error number xxxxx »
and on the screen I got a dialog claiming « the app is dedicated to PPC, can't run in Lion »

I'm too lazy to move back to 10.7.3 wink

Yvan KOENIG (VALLAURIS, France) dimanche 13 mai 2012 10:14:43

Offline

 

#9 2012-05-13 10:59:37 am

flex20
Member
From: Sydney, Australia
Registered: 2010-08-24
Posts: 163

Re: Folder action script to hide all files ending with "plist.lockfile"

Yes, I know, something like that can drive you up the wall.  I had something similar on a friend's MBP with 10.7.1.  Some scripts failing with strange messages, unexplained recovery items and even kernel panics.  I couldn't work out what was wrong.  Reinstalling the then current combo update (he used the delta update) didn't fix it.  What fixed it was reinstalling the then current whole OS X 10.7.1 from the App Store.  This is easy because Apple always provides the absolute current version of the whole OS X for installation or reinstallation.

If you still have unexplained problems with individual items, you may want to reinstall the whole 10.7.4 instead of trying to work out what's wrong with those items, specially since having one thing wrong, there may be other things wrong as well.

Last edited by flex20 (2012-05-13 11:12:14 am)

Offline

 

#10 2012-05-13 12:06:22 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Folder action script to hide all files ending with "plist.lockfile"

As I wrote, the command chflags behave well under 10.7.4 (installed with the combo installer).
I will work this way for some weeks and will make an installation on a blank HD when 10.8 will be delivered.
It's my workflow since the first time I installed OS X.

Yvan KOENIG (VALLAURIS, France) dimanche 13 mai 2012 19:06:15

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.038 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)