The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to display only hidden files useless79 Shell Programming and Scripting 7 11-12-2008 05:50 AM
Hidden Files in Linux Arun.Kakarla UNIX for Dummies Questions & Answers 3 07-05-2008 04:45 PM
find excluding the hidden files arunkumar_mca UNIX for Advanced & Expert Users 3 01-27-2008 11:45 PM
Finding Hidden files and protecting the folder containing hidden files from deletion pochaw Shell Programming and Scripting 4 12-22-2007 01:33 AM
Transferring hidden files with scp matrixmadhan UNIX for Dummies Questions & Answers 13 01-16-2007 04:00 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-07-2008
Omniwheel Omniwheel is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 1
Toggle Hidden Files Mac OS X

Hi all,

I have been using Ubuntu for 2 years now, and a few days ago I bought a Macbook. This is my first time using a Mac, so I have spent the better of two days learning the user interface, and configuring my Macbook. One thing I noticed is that there is no easy way to turn on and off hidden files, so I wrote a shell script to make it easy.

This is my first time ever making a script (I have previously never written a script on any OS), I hope you guys can comment on it, tell me whats good, bad, and how it can be done differently.

Specifically:

-Why does my terminal not close after the script is complete?

-Whats the best way to restart an application, ie one example has killall, the other uses osascript and envokes the quit command?

-Which application is safer?

-I named these files .command files so they can execute on double click, is the the best way to do it?

-Why do I have to execute 'open -a Finder' twice?

Code:
Example 1
#!/bin/sh
# This Application Makes Hidden Files Visible
# Note: The Application Will Close All Finder Windows
echo Warning This Application Will Close All Finder Windows!
echo Type y/n to Continue?
read answer
if [ "$answer" = "y" ]
then
    filesVisible=$(defaults read com.apple.finder AppleShowAllFiles)
    if [ "$filesVisible" = "0" ]
    then
        defaults write com.apple.finder AppleShowAllFiles -bool true
        killall Finder
    else
        defaults write com.apple.finder AppleShowAllFiles -bool false
        killall Finder
    fi
else
    exit
fi
exit
Code:
Example 2
#!/bin/sh
# This Application Makes Hidden Files Visible
# Note: The Application Will Close All Finder Windows
echo Warning This Application Will Close All Finder Windows!
echo Type y/n to Continue?
read answer
if [ "$answer" = "y" ]
then
    filesVisible=$(defaults read com.apple.finder AppleShowAllFiles)
    if [ "$filesVisible" = "0" ]
    then
        defaults write com.apple.finder AppleShowAllFiles -bool true
        osascript -e 'tell app "Finder" to quit'
        open -a Finder
        open -a Finder    
    else
        defaults write com.apple.finder AppleShowAllFiles -bool false
        osascript -e 'tell app "Finder" to quit'
        open -a Finder
        open -a Finder
    fi
else
    exit
fi
exit
Thanks,
Omniwheel
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0