Helper tool: need "chflags -R nouchg" running

Mac OSX specific forum
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 576
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Helper tool: need "chflags -R nouchg" running

Post by bembulak »

Hi all!

First let me say: I have just a very little Mac OS X experience, but some Linux experience. Using bash is ok for me.

Situation:
My father in law has an iMac with Mac OS 10.7 Lion. There seems to be a strange little bug, which prevents the "recycle bin" from being emptied. Apple has a workaround on their homepage that says one should open up a terminal, type "chflags -R nouchg " (<- with a space at the end of the line) and drop all the files from the recycle bin to the terminal.app.
Then press enter. AFAIK some kind of permissions get altered and then the recycle bin can be emptied as usually. No problem for me so far. But my father in law is not the kind of person that fires up a terminal and types commands...
So I tought, I'll write a little tool for him.
Just a window with an area, where he can drop the files on, a list where the files are listed and a button to execute that certain command.

The machine we're talking about has no development tools installed, no XCode and no PB. But I have the chance to do development on a 10.6 machine with PB 4.61 beta 1.

Now I played a little with the "Process" library and "RunProgram" (and such), but honestly: I'm not sure what's it all about.
For testing I altered the following code from the help/examples a little, but the output seems strange to me, I get no program data, just a 1 as exit code!

Code: Select all

chf = RunProgram("chflags", "-R nouchg", "", #PB_Program_Open|#PB_Program_Read)
  Output$ = ""
  If chf  
    While ProgramRunning(chf)
      If AvailableProgramOutput(chf)
        Output$ + ReadProgramString(chf) + Chr(13)
      EndIf
    Wend
    Output$ + Chr(13) + Chr(13)
    Output$ + "Exitcode: " + Str(ProgramExitCode(chf))  
    CloseProgram(chf)
  Else
    Output$ = "Could not start the program"
  EndIf
  
  MessageRequester("Output", Output$)
There is no program output. If I run the same command (chflags -R nouchg) in terminal.app directly I get a least a small hint about the options.
So my question is: how can I dertemine if the program works and what output it has? Normally, if everything works well, there should be no output at all on a *nix box at all and the exit code should be 0.

Any idea and help is apreciated, thanks!
cheers,

bembulak
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Helper tool: need "chflags -R nouchg" running

Post by Shardik »

You simply didn't set any path to a file or folder... :wink:
And you didn't take into account that on successful
execution there will be no output displayed in the console...

I have taken your example and modified it a little bit. In
its current state it will hide the PureBasic file GeeBee2.Bmp
in your PureBasic folder. Before execution open the Finder
and display the contents of the folder obtained by a previous

Code: Select all

Debug #PB_Compiler_Home + "Examples/Sources/Data"
You should see the file Geebee2.bmp...

After execution of the below code example close the above
folder and reopen it: the file Geebee2.bmp is not visible
anymore.

To make Geebee2.bmp visible again just comment the line

Code: Select all

#Attribute = "hidden"
and uncomment

Code: Select all

; #Attribute = "nohidden"
After execution of the modified code below Geebee2.bmp
should be visible again... :wink:

Code: Select all

#Attribute = "hidden"
; #Attribute = "nohidden"
#FilePath = #PB_Compiler_Home + "Examples/Sources/Data/GeeBee2.Bmp"

chf = RunProgram("chflags", #Attribute + " " + #FilePath, "", #PB_Program_Open|#PB_Program_Read)
Output$ = ""
If chf 
  While ProgramRunning(chf)
    If AvailableProgramOutput(chf)
      Output$ + ReadProgramString(chf) + Chr(13)
    EndIf
  Wend
  If Output$ <> ""
    Output$ + Chr(13) + Chr(13)
    Output$ + "Exitcode: " + Str(ProgramExitCode(chf))
  Else
    Output$ = "File GeeBee2.Bmp has been successfully " + #Attribute
  EndIf
  CloseProgram(chf)
Else
  Output$ = "Could not start the program"
EndIf

MessageRequester("Output", Output$)
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Re: Helper tool: need "chflags -R nouchg" running

Post by michel51 »

Shardik wrote:You simply didn't set any path to a file or folder... :wink:
And you didn't take into account that on successful
execution there will be no output displayed in the console...

I have taken your example and modified it a little bit. In
its current state it will hide the PureBasic file GeeBee2.Bmp
in your PureBasic folder. Before execution open the Finder
and display the contents of the folder obtained by a previous

Code: Select all

Debug #PB_Compiler_Home + "Examples/Sources/Data"
You should see the file Geebee2.bmp...

After execution of the below code example close the above
folder and reopen it: the file Geebee2.bmp is not visible
anymore.

To make Geebee2.bmp visible again just comment the line

Code: Select all

#Attribute = "hidden"
and uncomment

Code: Select all

; #Attribute = "nohidden"
After execution of the modified code below Geebee2.bmp
should be visible again... :wink:

Code: Select all

#Attribute = "hidden"
; #Attribute = "nohidden"
#FilePath = #PB_Compiler_Home + "Examples/Sources/Data/GeeBee2.Bmp"

chf = RunProgram("chflags", #Attribute + " " + #FilePath, "", #PB_Program_Open|#PB_Program_Read)
Output$ = ""
If chf 
  While ProgramRunning(chf)
    If AvailableProgramOutput(chf)
      Output$ + ReadProgramString(chf) + Chr(13)
    EndIf
  Wend
  If Output$ <> ""
    Output$ + Chr(13) + Chr(13)
    Output$ + "Exitcode: " + Str(ProgramExitCode(chf))
  Else
    Output$ = "File GeeBee2.Bmp has been successfully " + #Attribute
  EndIf
  CloseProgram(chf)
Else
  Output$ = "Could not start the program"
EndIf

MessageRequester("Output", Output$)
Nice snippet and very helpfull.
But I have another question: I know the programname "open" (command "runprogram"), and now I see "chflags".
Is there a list anywhere with the complete programnames and there description?
I don't have found such a list yet.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 576
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Re: Helper tool: need "chflags -R nouchg" running

Post by bembulak »

Thanks a lot Shardik!
It seems to work now. The example with PB's Data folder really helped. Then I also dug through the manpages of chflags and now I also understand it's behaviour better.

@michel51:
These commands are just bash/shell commands. You can take nearly any Unix/FreeBSD/Linux bash tutorial and apply it to OS X. It's pretty similar.
http://ss64.com/osx/
http://en.wikipedia.org/wiki/Bash_%28Un ... rnal_links
http://tldp.org/LDP/Bash-Beginners-Guide/html/

Thanks for your help, guys!
cheers,

bembulak
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Helper tool: need "chflags -R nouchg" running

Post by Shardik »

michel51 wrote:But I have another question: I know the programname "open" (command "runprogram"), and now I see "chflags".
Is there a list anywhere with the complete programnames and there description?
I don't have found such a list yet.
"chflags" is a BSD Unix console command. You may take a look into its use and
syntax:
https://developer.apple.com/library/mac ... ags.1.html

If you try a Google search with "chflags Lion" you will see a lot of links that
demonstrate how to make visible again the Applications folder that was visible
in Snow Leopard and previous MacOS X versions but is hidden in Lion. With
the command

Code: Select all

chflags nohidden ~/Library/
typed in a console you can make visible the Applications folder in MacOS X Lion... :wink:

You have to use "Open" as a command if you want to start an application or open
the application connected to your given file, for example a weblink or a pdf file...
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Re: Helper tool: need "chflags -R nouchg" running

Post by michel51 »

@bembulak, @shardik

Thanks for your answers, comments and links.
They were very helpful.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Post Reply