简体   繁体   中英

How To Make a command with AppleScript to Terminal to free ram space OSX ML

I'd like to write an AppleScript command that can run Terminal and write "purge" , press return and then cmd-q.

I tried this way:

tell application "terminal" keystroke ??????????? (I don't know how to use keystrokes commands!) end tell

I'd like to compose this command with AppleScript to free RAM space only starting a script without third party apps.

tell application "Terminal"
    activate

    tell application "System Events"
        keystroke "sudo"
        keystroke return
    end tell

end tell

or the answer by Lauri, which does the same thing without showing the Terminal or having to activate it.

Applications that free inactive memory are a huge scam. Read some of the questions linked here . But if you really have to do it, use do shell script :

do shell script "purge"

You have two options:

  1. Shell scripting (runs the command without even opening Terminal, best option)
  2. Keystrokes, as you have said

Shell scripting:

do shell script "purge"

Keystrokes:

tell app "Terminal" to activate
tell app "System Events" to keystroke "purge"
tell app "System Events" to keystroke return
tell app "Terminal" to quit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM