Applescript command when closing a window

Discussion in 'Mac Programming' started by ElectricMan5, May 24, 2009.

  1. macrumors regular

    I keep my Halo 2 files in a hidden folder, with a . in front of the name. The only thing is, when I run it, it says that it cannot open because of the .

    I'm trying to make an applescript, which when its run, moves the folder to the desktop , open up the app, and when the app is closed, it moves it back to it's location.

    How do i move folders, cause when I record, nothing appears when I move the folder, and how do i issue a command when the window is closed?

  2. macrumors 65816


    "mv" is the command.

    mv /Users/user/path/to/.Halo /Users/user/Desktop

    You can also replace /Users/user/ with ~/.

    mv ~/path/to/.Halo ~/Desktop
  3. macrumors 68040


    Whose machine are you hiding halo 2 on?
    Who do you want/need to hide halo 2 from on your machine?

    Based on the answer to this, there might be a better way to achieve what you are wishing to achieve.

  4. macrumors regular

    I don't think those will make a difference...

    I just want a command. I have the command for moving, but nothing yet for moving the folder back when the program quits... Thanks!
  5. macrumors 68040


    I think it will make a difference.

    If you are wanting to run it on a machine that isn't yours, you might consider putting it on a thumb drive or something, that way there's nothing to worry about, you just take it with you. Then you aren't using resources that aren't yours (i guess you're using the CPU time while you're playing, but unless the machine should be crunching numbers all the time, the owner probably won't notice they're missing).

    If it's your own machine, but you just don't want others to know it's there you can probably accomplish this with multiple users and unix permissions. If you can't force others to use a separate login, you could make one for yourself just for playing the game, and make sure that the ownership of the folder that contains this folder isn't readable to anyone else, and the folder itself is not, etc.

    Otherwise, i would write a shell script that moves the folder to a non-hidden place, runs it, then when the game exits, renames it somewhere hidden. EDIT: i don't know applescript well. There is assuredly a way to do what i suggested using applescript, but i know shell better, so i'd do it that way.

  6. macrumors regular

    It's my own machine, and it has nothing to do with users. Please, I asked for what I want, I know what I'm doing. Also, mv /Users/user/path/to/.Halo /Users/user/Desktop doesn't work at all. I know mv is the code, the putting the path in doesn't work.
  7. macrumors 68040


    mkdir .hiddenfolder
    cd .hiddenfolder
    <create shell script,, set to executable>
    echo "This is the hidden program"
    <create shell script,, set to executable>
    mv .hiddenfolder nothiddenfolder
    . ./nothiddenfolder/
    mv nothiddenfolder .hiddenfolder
    When is run, it moves the hidden folder to a non-hidden folder, then runs the program, then moves the folder back to hidden.

  8. macrumors regular

    Is there a way to do this via Applescript though?
  9. macrumors 65816


    Yes, something like:

    on run
    do shell script "mv ~/path/to/.Halo ~/Desktop"
    end run
    MRoogle "do shell script" and you should see plenty of examples here.

    And you may need to replace the /'s to //'s because AS uses the slash like an escape character.


Share This Page