Mac Script Check If App Running And Close It

To check whether an app with a particular bundle ID is running, use this code: tell application 'System Events' set ids to bundle identifier of every application process if ids contains 'com.apple.safari' then return 'Running' else return 'Not running' end if end tell. Sep 05, 2014 Quitting apps gracefully is typically done through the appropriate application menu by choosing “Quit”, but the Mac GUI is obviously inaccessible from the command line of Mac OS X. So when most command line users are confronted with the need to exit an application, they wind up using the ‘kill’ command to terminate the process.

Knowing which Apps or Processes are running on your Mac is important, because some of these Apps could be slowing down your Mac. You will find below 4 different ways to show All the Running Apps and Processes on your Mac.

Check that you have the most current version of the app, and if not, update it. This step is essential following an update to the Mac operating system. In many cases, updating the affected app cures the problem.

Why to See All Running Apps and Processes on Mac

In case you are coming from a Windows computer, you must be used to opening the Task Manager on your Windows computer, in order to take a look at all the running apps and processes on your computer.

In the case of a Mac, there are multiple ways to see all the Running Apps and Programs, ranging from the simple option of using the Dock to using the Terminal command.

In general, the purpose of taking a look at All the Running Apps and Programs on your Mac is to get an idea of which programs are actively running on your Mac, what resources they are using and also to rule out the possibility of any unnecessary programs running in the background and using up resources on your computer.

Show All Running Apps and Processes On Mac Using the Activity Monitor on Mac

Activity Monitor can be described as the Mac equivalent of a Task Manager in a Windows computer. The Activity Monitor provides a very good view of the App and processes running on your Mac and the amount of resources being uses by these Apps and Processes.

1. Click on the Finder icon located in the left corner of the Dock (See image below)

2. On the next screen, click on Applications in the left sidebar menu and then click on the Utilities folder.

3. In the Utilities folder, click on Activity Monitor which should be the first item in Utilities Folder (See image below)

4. Once Activity Monitor opens, you will be able see a list of All the Processes or Applications currently running on your Mac (See image below)

As you can see in the above image, there are 5 different tabs in the Activity Monitor -> CPU, Memory, Energy, Disk and Network.

Clicking on each tab will show you more details, for example, clicking on the Memory Tab will show you how much memory each process is using. Similarly, clicking on the CPU tab will show you the amount of CPU being used by each of these Apps and Processes running on your Mac.

5. To view more info about a specific Process or Application, simply click on the Application/Process and then click on the i icon button located at the top left Corner of the screen (See image below).

6. To force quit an application or process through Activity Monitor, simply click on the application you would like to force quit and then click on the x button, located at the top left side of your screen (See image below)

App

Show All Running Apps On Mac Using Force Quit Applications Manager

Another method to check all the Running apps and programs on your Mac is through the Force Quit applications manager on Mac.

1. Click on the Apple icon in the top menu bar of your Mac and then click on Force Quit Application in the drop-down menu (See image below).

2. This will open the Force Quit Applications manager which will show you all running apps on your Mac

3. To force quit one of these applications, simply click on the application from the list and click on the Force Quit button.

Show Running Apps and Processes On Mac using the Terminal Command

The Terminal also shows you a detailed view of which applications and processes are running on your Mac, along with the percentage of CPU used by each of these applications/processes.

1. To open Terminal on your Mac, do a spotlight search for the Terminal by pressing the Command + Space keys on your Mac keyboard and searching for Terminal in Spotlight Search. (See image below)

2. Next double click on the Terminal option or press the enter key on your Mac’s keyboard to open up Terminal

3. In the terminal type in top –o cpu and press the enter key on your keyboard

This will show you a list of all running apps and processes with the apps consuming the most CPU at the top of the list.

4. To reorganize this list close the Terminal and reopen it. Once Terminal reopens type in top –o rsize and press the enter key on your keyboard.

Now applications or processes which are using the most memory will be listed at the top of the list and the application or processes using the least memory will be listed at the bottom of the list.

Show Running Apps Through Dock

The easiest way to view running apps on your Mac is by simply taking a look at your dock.

All running applications will have a black dot underneath the applications icon (See image below)

While this method is easy to follow, it sometimes will not show you all apps running in the background and does not even show you which processes are running in the background.

This method also does not give you much detail, like how much memory each application is using or how much CPU is being used by each application.

Running the Mac OS X maintenance scripts

Mac® OS X is a UNIX®-based system, built in part on both BSD® and FreeBSD®. UNIX systems run scheduled maintenance routines — known as maintenance scripts — to clean up a variety of System logs and temporary files. By default, these are executed between 03:15 and 05:30 hours local time, depending on the script.

If your Mac is shut down or in sleep mode during these hours, the maintenance scripts will not run. [1] This results in log files that will grow over time, consuming free space on your Mac OS X startup disk.

If your Mac is shut down or left in sleep mode overnight, the maintenance scripts should be run manually on a regular basis… unless you plan on devoting a large portion of your hard drive to the files cleaned-up by these routines!

This FAQ, derived from our book Troubleshooting Mac OS X, provides:

  • Procedures for manually running the maintenance scripts.
  • Determining when the maintenance scripts last ran.
  • The maintenance performed by the scripts.
  • How the scripts are launched on a schedule.

More information about maintaining Mac OS X can be found in our 'Maintaining Mac OS X' FAQ.

Manually running the maintenance scripts

The easy way

Download and install a third-party utility, such as Cocktail or Yasu, that provides a function for running the maintenance scripts. You may find additional solutions by searching MacUpdate or VersionTracker™. Employ the version of the utility that is compatible with to the version of Mac OS X you are using.

These utilities permit running any individual maintenance script — daily, weekly, or monthly — or all of them. For example, running all three scripts weekly is a good habit if your Mac is frequently shutdown or in sleep mode overnight.

While we have not tested it, we have read positive reports from users of the freeware application Anacron. It runs the maintenance scripts automatically if the computer is awake and the scripts have not run when scheduled. As with other utilities, employ the version of Anacron that is compatible with the version of Mac OS X you are using..

The Terminal way

Using your Admin account, you can run all three maintenance scripts at once:

  1. Open Terminal, located in the Macintosh HD > Applications > Utilities folder.
  2. At the Terminal prompt, type the following, exactly as written:
  3. Press Return.
  4. Type your Admin password when prompted, then press Return.

All three scripts will run in sequence. There is no visual feedback while the scripts execute. You will know they are completed when the Terminal prompt returns.

You can also run the scripts individually. For example, to run just the daily script, you would type the the following command in step 2:

  • sudo periodic daily

Determining when the maintenance scripts last ran

You can run a Terminal command to quickly check the date and time stamps of the log files associated with each maintenance script. This indicates when the scripts' logs were last updated, hence when the scripts were last executed.

  1. Open Terminal, located in the Macintosh HD > Applications > Utilities folder.
  2. At the Terminal prompt, type the following, exactly as written:
    1. ls -al /var/log/*.out
  3. Press Return.

You will see output similar to the following:

-rw-r--r-- 1 root wheel 467984 8 May 10:40 /var/log/daily.out

-rw-r--r-- 1 root wheel 1258 8 May 10:43 /var/log/monthly.out

-rw-r--r-- 1 root wheel 198378 8 May 10:43 /var/log/weekly.out

In this example, the scripts last ran on 8 May of the current year, between 10:40 and 10:43 local time. The date and time stamps in the example are the result of running the scripts manually via Terminal. If the scripts were run automatically on their default schedule, their date stamps would vary and their time stamps would indicate executions between 03:15 and 05:30 hours.

The maintenance performed by the scripts

Each maintenance script — daily, weekly, and monthly — has a specific function. Their functions have varied over different versions of Mac OS X.

Mac script check if app running and close it is going
  • The daily script removes old log files, 'scratch' and 'junk' files, backs-up the NetInfo database (Mac OS X 10.4 Tiger® and earlier), reports a variety of system and network statistics, and rotates the system.log file. Under Tiger, the daily script also cleans up scratch fax files and prunes asl.log, the log file for the then-new Apple System Logging facility. Under Mac OS X 10.5 Leopard®, the daily script also prunes the asl.db file that replaced the asl.log file for Apple System Logging.
  • The output from the daily script is written to the /var/log/daily.out file, which can be viewed in Console.
  • By default, the daily script is scheduled to run daily at 03:15 hours local time.
  • The weekly script rebuilds the locate and whatis databases. Depending on the version of Mac OS X, it also rotates the following log files: ftp.log, lookupd.log, lpr.log, mail.log, netinfo.log, ipfw.log, ppp.log, and secure.log
  • The output from the weekly script is written to the /var/log/weekly.out file, which can be viewed in Console.
  • By default, the weekly script is scheduled to run every Saturday at a specific time. Under Tiger and later, it runs at 03:15 hours local time. Under Mac OS X 10.3 Panther® and Mac OS X 10.2 Jaguar it runs at 04:30 hours local time.
  • The monthly script reports per-user usage accounting and rotates — depending on the version of Mac OS X — the wtmp, install.log, and cu.modem.log files.
  • The output from the monthly script is written to the /var/log/monthly.out file, which can be viewed in Console.
  • By default, the monthly script is scheduled to run on the first of the month at 05:30 hours local time.

Mac Script Check If App Running And Close Items

Mac script check if app running and close it is working

How the scripts are launched on a schedule

How the schedule for each script is specified depends on the version of Mac OS X.

Scheduling under Panther and Jaguar

Under Panther and Jaguar, the schedule is specified in the System crontab file. You can easily view or edit this file with the donationware utility Cronnix. The cron process launches the scripts based on the schedule specified in crontab.

Scheduling under later versions of Mac OS X

Introduced in Tiger, the launchd process invokes each script on a schedule specified in a script-specific property list (.plist file) in the /System/Library/LaunchDaemons directory. The specific property list for each script is as follows:

  • daily script: com.apple.periodic-daily.plist
  • weekly script: com.apple.periodic-weekly.plist
  • monthly script: com.apple.periodic-monthly.plist

Additional information about launchd can be found in the Apple Developer Connection document System Startup Programming Topics.

How the timer used by launchd handles sleep time has led many to incorrectly believe that they no longer need to run the maintenance scripts and that the scripts are run automatically if the Mac was asleep or shutdown at the scheduled time.

Mac Script Check If App Running And Close It Is Hacked

While it may appear that launchd executes the maintenance scripts 'on the fly' if the computer is asleep or shutdown at the appointed time, this is a side effect of how the timer treats the time the computer has spent in sleep mode. The timer used by launchd does not count sleep time. If your Mac is asleep at the scheduled time when a given script is supposed to run, the script may run later that day at a time shifted by the amount of time the Mac was asleep. However, if you restart your Mac before the time-shifted execution time, pending events are lost and the script will not run off-schedule: the next chance for the script to run will be at its regularly scheduled time.

If you regularly restart your Mac and the computer regularly sleeps or is shut down at the scheduled times, it's possible that the scripts will never run, hence one should still run them manually, such as on a weekly basis.

The sleep time shift is also cumulative. For example, if you don't restart your Mac for weeks or months at a time, but let it sleep when not in use, this can result in:

  • The daily script running once every few days or never.
  • The weekly script running once every few weeks or never.
  • The monthly script running once every few months or never.
Mac script check if app running and close it is safe

The time shift in each case is the total amount of time the Mac has spent in sleep since its last restart. If you have a process that writes heavily to the logs, you can end up devoting good hard disk space to the log files.

Related links

Mac Script Check If App Running And Close It Is Open

  • Maintaining Mac OS X.

Notes

And

[1] If you log out from your Mac OS X system and leave it with the Login Window displayed, your Mac can still enter sleep mode. When left at the Login Window, your Mac will enter sleep mode based on the settings specified by the last Admin user in System Preferences > Energy Saver. Therefore, if you want to leave your Mac with the Login Window displayed and still have the nightly Mac OS X maintenance routines run automatically, an Admin user must set System Sleep to Never in the System Preferences > Energy Saver > Sleep tab.