Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible improvements? #3

Open
grahampugh opened this issue Mar 15, 2017 · 3 comments
Open

Possible improvements? #3

grahampugh opened this issue Mar 15, 2017 · 3 comments
Assignees

Comments

@grahampugh
Copy link

Hey ftiff,

We're using this app a lot: thanks! A couple of things I've come across using this app:

  1. If the app you are trying to close doesn't exist, it spits out error 132. I think it should exit 0, since there is no problem if there is no running app to close :) I added a check in our run script to account for this.

  2. I don't know if you would like to include this in the app itself, but you can determine the required AppBundleID for an application using PlistBuddy, so no need to manually find it out. See below.

We package the unmodified app to install to /Library/Application Support/JAMF/bin/MacAdminQuitApp.app and I have a template script in Jamf Pro to close whatever app I enter into Parameter 4:

#!/bin/bash

## =========================================================================
# MacAdminQuitApp template script
# Graham Pugh, 2016-11-29
## =========================================================================
## This script takes Casper script Parameter 4 for the Application name
## and the appBundleID

# Inputted variables
appName="$4"

# example for standalone testing
# appName="SuperDuper!.app"

# Path to MacAdminQuitApp
MacAdminQuitApp="/Library/Application Support/JAMF/bin/MacAdminQuitApp.app"

# Add .app to end when providing just a name e.g. "TeamViewer"
if [[ ! $appName == *".app"* ]]; then
	appName=$appName".app"
fi

# Add standard path if none provided
if [[ ! $appName == *"/"* ]]; then
	appToClose="/Applications/$appName"
else
	appToClose="$appName"
fi

if [[ -d "$appToClose" ]]; then
    # Extract the appBundleID from the chosen application using PlistBuddy
    appBundleID=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$appToClose/Contents/Info.plist")
    # run the script
    "${MacAdminQuitApp}"/Contents/MacOS/MacAdminQuitApp -appPath "$appToClose" -appBundleID "$appBundleID"
    echo "$appToClose closed."
else
    # App doesn't exist!
    echo "$appToClose is not installed. Nothing to do."
fi
@ftiff
Copy link
Collaborator

ftiff commented Mar 15, 2017

Hi Graham,

Thanks for your report!

If the app you are trying to close doesn't exist, it spits out error 132. I think it should exit 0, since there is no problem if there is no running app to close :) I added a check in our run script to account for this.

I understand the issue… I was doing an exit(1) thinking this would use the exit code "1"… but this is not recommended. I see "1" on my Mac, though.
I'm not sure always exiting successfully is the way to go here…

I don't know if you would like to include this in the app itself, but you can determine the required AppBundleID for an application using PlistBuddy, so no need to manually find it out. See below.

Looks like I wasn't clear enough in the doc for this one :)
-appPath is sufficient for most apps (eg. /Application/iTunes.app).
But sometimes you need to quit background (agent) applications, that only have a Bundle ID. For example you might want to quit the helper. In my case I had to quit both the Citrix application and the Citrix agent.

Does it makes sense?

I really like your script. I will add it to the repo if that's ok?

@ftiff ftiff self-assigned this Mar 15, 2017
@ftiff
Copy link
Collaborator

ftiff commented Mar 15, 2017

@grahampugh
Copy link
Author

grahampugh commented Mar 15, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants