Need an Applescript to make 10,000 folders

Discussion in 'Mac Programming' started by millap, Sep 12, 2007.

  1. millap macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #1
    This may seem like a strange request, so let me explain...

    I have most of my movie collection ripped to a hard drive, which is easily accessible using Front Row. Most of the films are rated Certificate 15 or above, therefore I don't want the kids to able to access these films easily.

    I would like to create a nested folder structure starting with a folder called "Enter PIN". Inside this would be 10 more folders called "0" .... "9" , and inside each of those folders would be 10 more, and so on... until the nest is 4 levels deep. This would then allow me to move all of my films to a PIN of my choice, whilst still keeping all of the children's content at the top level, outside of the PIN folder structure.

    Any help on how to to do this would be much appreciated.
    Thanks
     
  2. yetanotherdave macrumors 68000

    yetanotherdave

    Joined:
    Apr 27, 2007
    Location:
    Bristol, England
    #2
    I think you are better off keeping the movies you want restricted to a password protected disk image (maybe one disk image for each movie), as it wont take long for your kids to find the files if they want to (using disk inventory x or similar)

    although that would probably break front row, but you could copy the film to your films folder and delete when watched, preserving the password protected disk image
     
  3. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #3
    Thanks for the quick reply...

    I don't actually need the security to be that good, as this is all run from a Mac mini which is connected directly to the TV and does not have a keyboard or mouse attached, so the Apple remote is the only interface that the kids have.

    I manage the content remotely from another machine over ethernet, so the lack of keyboard and mouse isn't a problem.
     
  4. antibact1 macrumors 6502

    Joined:
    Jun 1, 2006
    #4
    How old are your children?
     
  5. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
  6. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #6
    So you think you can "hide" a file in one of the 10,000 folders? That will not work. Well it might if the kid was 7 years old but I could find the file in 10 seconds. I kid who can type and read could post a question on this forum and learn how to find the file in 10 seconds.

    Even if spotlight was not available there is a commend called "find" which could look in 10,000 folders very quickly looking for files that match a given pattern. Other commands show the size of a folder and anyone could simply follow the chain of larger folders

    Why not simply set the permission to "no access". UNIX has had the ability to grant or deny access to specific file to a specific user for maybe the past 25 years now. The system works well.
     
  7. antibact1 macrumors 6502

    Joined:
    Jun 1, 2006
    #7
    This would probably be the best idea. If you make a symbolic link to /Volumes/WHATEVER where whatever is the name of your encrypted volume, when you mount the volume, Front Row will be able to access the content. When it is not mounted, Front Row will see simply an invalid symbolic link which should not cause any difficulties. As your kids are so young, if they inadvertently get into that complicated PIN structure, they aren't going to be able to figure out how to get back and find Sponge Bob or Nemo.
     
  8. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #8
    The Symbolic link idea sounds good to me... I'll give that a go.
    Thanks for the input everyone.
     
  9. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #9
    Hah, I like your idea. It will be interesting to see if/when the kids crack it.

    Anyway, I'm not good with AppleScript, but here's a copy and paste method that will get you there quickly--quicker than you'd think. A little hard to explain, but it's recursive.

    1. Just anywhere, create four folders called level1, level2, level3, level4.
    2. Open the parent of these folders and put it in columns view so you can see all of them.
    3. Select level1 and create 10 folders called 0, 1, 2, 3, ... 9. You can create then easily by pressing Cmd-Opt-N while level1 is selected.
    4. Select the 10 folders your created and press Cmd-C (copy)
    5. Select level2 and press Cmd-V (paste). Select level3 and press Cmd-V and Select level4 and press Cmd-V.

    Now you've got four folders, each with subfolders 0, 1, ..., 9.

    6. Go back to level2 and select folder 0. Here's where you really want to be in columns mode. Press Cmd-V. This will copy the folders 0-9 into folder 0. Press the down arrow key which will select folder 1. Press Cmd-V again. Repeat, pressing down-arrow and then Cmd-V until you have pasted into all 10 folders.
    7. Now select the ten folders at the top of level2 and press Cmd-C.
    8. Go to level3 and select folder 0. Press cmd-v, down-arrow, cmd-v, down-arrow, etc. until, again, you've pasted into all ten folders.
    9. Now select the ten folders at the top of level3 and press Cmd-C.
    10. Again, go to level4 and select folder 0. Press cmd-v, down-arrow repeated until you fill all ten folders again.

    Now, you can rename level4 to "Enter PIN" and move it to where you want it.
    Make sense?

    NOTE: I just tried this on my mac and it worked. By the time you are pasting into the subfolders of level4, it really slows down. Once, Finder even crashed! I'd take it slow at this level.
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    Can probably be done with Applescript, but still learning it. I did come up with a Bash script solution though. I've tested it and does work, though as you can imagine does take a moment to run. Save this in a file and put in the directory you want to folders created. You'll need to set the permissions of the script file to be executable (in terminal do, "chmod 755 scriptFileName"). Let me know if you have problems getting it to run.

    Code:
    #!/bin/bash
    mkdir 0
    mkdir 0/0
    mkdir 0/0/0
    mkdir 0/0/0/0
    
    for a in 1 2 3 4 5 6 7 8 9
    do
      for b in 1 2 3 4 5 6 7 8 9
      do
        for c in 1 2 3 4 5 6 7 8 9
        do
          for d in 1 2 3 4 5 6 7 8 9
          do
            cp -R 0/0/0/0/ 0/0/0/$d
          done
          cp -R 0/0/0/ 0/0/$c
        done
        cp -R 0/0/ 0/$b
      done
      cp -R 0/ $a
    done
    exit 0
     
  11. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #11
    Thanks very much guys. I'll give this a go as soon as i get a chance tomorrow, as it's after midnight here in the UK at the moment.
     
  12. savar macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #12
    Haha, I like the idea and the implementation...one comment on your solution: "mkdir -p" would make more sense than "cp -R", but thats probably nitpicking.
     
  13. pianojoe macrumors 6502

    pianojoe

    Joined:
    Jul 5, 2001
    Location:
    N 49.50121 E008.54558
    #13
    If your kid does know how to work the Finder, it will
    1. switch to list view
    2. Alt-click the triangle of the folder that encloses all other folders, e.g. "Movies".

    This way your PIN will be cracked in less than a second.
     
  14. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #14
    Yes I realise this, but as I've said before... There's no interface for them to even access the finder. It's just Front Row using the Apple Remote.

    I am not looking for some kind of super secure encryption technology here that is totally unbreakable. I just want a very simple solution that works using the Front Row interface, that will work for maybe a couple of years until the kids are smart enough to get around it. By that time, hopefully Front Row 3 will include some form of parental controls anyway.
     
  15. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #15
    That may be, I'm not bash scripting expert. This is the most advance thing I've put together. I've only done maybe 3 scripts ever o I was just happy to come up with a solution.

    Millap, have you had the chance to try my solution? If you need help let me know, it won't take much effort at all.
     
  16. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #16
    No not yet, I'm at work at the moment and don't have access to my Mac. I plan on trying as soon as I get home tonight. I guess that will be about 12:30 US time. I'll post and let you know as soon as I can.

    Many thanks once again
     
  17. MongoTheGeek macrumors 68040

    MongoTheGeek

    Joined:
    Sep 13, 2003
    Location:
    Its not so much where you are as when you are.
    #17
    I ran it for s&g and it worked like a champ.
     
  18. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #18
    OK, I might need some help with this...

    I've pasted the code into a TextEdit document and saved it in a folder on the desktop called EnterPIN.
    I had to save it as PIN.rtf since there wasn't a plain text option.
    I renamed it afterwards to simply PIN without the extension.
    I managed to launch Terminal and set the default directory to iMac:~/desktop/EnterPIN
    And I then did the chmod 755 scriptFileName step.

    How do I actually run the script ?

    Sorry to ask, but this is my first time using Terminal.

    EDIT: It's OK, I figured it out.

    I wasn't sure if the .rtf file was going to cause a problem, so I just downloaded something called TextWrangler, which let me save it as plain text. Since you called this a bash script, I figured try typing "bash pin". It worked perfectly and I now have all the folders.

    Thanks again to everyone
     
  19. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #19
    Having it saved as RTF may cause problems (likely will). In TextEdit under the Format menu there's an option for making it plain text. Also, save the file to where you want all of the files created. You could move them all later, by why not now?

    Once that part is done, in terminal go to the directory with the file. To run the script: "./PIN" (without quotes). It won't give any feedback unless there's an error. It'll take a few seconds to run before the prompt comes back. Meanwhile if you have Finder open you'll see it steadily creating all of the folders. If the command says something about PIN not being a command it means the permission didn't get set right, or typo. Give that a shot.

    Edit: Never mind then, you got it. I've never tried calling a script with bash, but makes sense that it works as well as what I state above. Glad it worked.
     
  20. millap thread starter macrumors regular

    Joined:
    Aug 10, 2007
    Location:
    United Kingdom
    #20
    Just tried using it with Front Row, and it works great... just what I was looking for.

    I've moved all of my movies to a new 'Movies' folder that sits at the root of my hard drive so that the films are easy to find using the Finder. As I said before, not looking for a secure option outside of Front Row. I then created an Alias to Movies and dropped it into the PIN structure.

    It all works perfectly, and would probably make a nice little app for anyone looking to do something similar, perhaps with a GUI and an option to change the PIN if needed.

    I'm toying with the idea of actually arranging my movies into sub folders, one for each Certificate rating, and then having different PINs for each rating. Not that I actually need this, but it's certainly possible to do it now. Again, this would make a nice little app for anyone looking to build a media center.

    Please let me know if anyone decides to write this in the future. For now, I'm very happy.
     
  21. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #21
    You know that this all comes crashing down once your children learn to use the ls -r command (or find, or any other UNIX program), piped into grep, as ChrisA stated.

    If you want to hide your movies, put them in a seperate user account. You realize that each folder you create consumes 4kb, so multiply that by how many folders you're making and you're wasting quite a bit of space. So you spent 40MB to do absolutely nothing.
     
  22. panoz7 macrumors 6502a

    panoz7

    Joined:
    Nov 21, 2005
    Location:
    Raleigh, NC
    #22
    Did you even read this thread before you revived it? Here's a quote:

    From what I gather the kids won't have access to a command line or even a keyboard... only the front row remote. His folder system actually seems like a pretty good way to achieve something that front row should have built in by default.
     
  23. devnill macrumors newbie

    devnill

    Joined:
    Sep 20, 2007
    Location:
    London town
    #23
    separate user account?

    Once your the other users learn to use terminal with the "locate" command or
    'find . -name "movie" -print' the folder structure will not be of any use.
    A separate user account with the correct permissions mentioned in the above posts seems to be the best plan.:(
     
  24. GaseousPlatypus macrumors member

    Joined:
    Jul 8, 2004
    #24
    It's like nobody even bothered to read anything the OP posted.

    The kids CAN'T get around the PIN system (despite how silly I think it is) because they have NO WAY to interact with the computer except via the FrontRow Remote.

    If your remote can run bash scripts or hell even invoke a Spotlight menu (AND type in the names of files you want to find) then I'd like to know why mine's only got 6 buttons.
     

Share This Page