It is currently Tue Jun 18, 2013 6:26 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Helper tool: need "chflags -R nouchg" running
PostPosted: Tue Mar 06, 2012 4:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Mar 06, 2006 3:53 pm
Posts: 530
Location: Austria
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:
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!

_________________
Image


Top
 Profile  
 
 Post subject: Re: Helper tool: need "chflags -R nouchg" running
PostPosted: Tue Mar 06, 2012 8:10 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 821
Location: Germany
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:
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:
#Attribute = "hidden"
and uncomment
Code:
; #Attribute = "nohidden"

After execution of the modified code below Geebee2.bmp
should be visible again... :wink:
Code:
#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$)


Top
 Profile  
 
 Post subject: Re: Helper tool: need "chflags -R nouchg" running
PostPosted: Tue Mar 06, 2012 8:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 21, 2005 10:21 pm
Posts: 285
Location: Germany
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:
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:
#Attribute = "hidden"
and uncomment
Code:
; #Attribute = "nohidden"

After execution of the modified code below Geebee2.bmp
should be visible again... :wink:
Code:
#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.11(x64), V 5.10(X64)


Top
 Profile  
 
 Post subject: Re: Helper tool: need "chflags -R nouchg" running
PostPosted: Wed Mar 07, 2012 8:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Mar 06, 2006 3:53 pm
Posts: 530
Location: Austria
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!

_________________
Image


Top
 Profile  
 
 Post subject: Re: Helper tool: need "chflags -R nouchg" running
PostPosted: Wed Mar 07, 2012 8:50 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 821
Location: Germany
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:
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...


Top
 Profile  
 
 Post subject: Re: Helper tool: need "chflags -R nouchg" running
PostPosted: Wed Mar 07, 2012 6:27 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 21, 2005 10:21 pm
Posts: 285
Location: Germany
@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.11(x64), V 5.10(X64)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye