Shell scripting, check for a folder, copy to it if it exists then self destruct

Discussion in 'Mac Programming' started by Mr Rabbit, Jun 26, 2014.

  1. Mr Rabbit macrumors 6502a

    Mr Rabbit

    May 13, 2013
    Thanks to my heavy workload at the moment I'm drawing a blank on piecing this together. I can piece together bits and pieces of this whole task but for the life of me I can't put it all together.

    I'm wanting to build a script that will execute when a Mac user logs in. The script checks for the presence of a folder ("~/Library/Application Support/Firefox" specifically). If it finds the folder it copies a file into one of it's subfolders and then removes itself, along with the login hook needed to run the script in the first place. If it does NOT find the specified folder then it exits quietly and runs again the next time the user logs in.

    Any ideas?
  2. NogbadTheBad macrumors regular


    Aug 28, 2009
    United Kingdom
    Try this :-

    DIRECTORY=~/Library/Application Support/Firefox
    if [[ -d "${DIRECTORY}" && ! -L "${DIRECTORY}" ]] ; then
    echo "Directory exists\n"
    echo "Directory doesn't exist\n"

Share This Page