Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/zsh
- # shellcheck shell=bash
- # applaunched v0.1
- # LSIsAppleDefaultNoOverrideForType workaround for pkg & mpkg installer files (macOS)
- export LANG=en_US.UTF-8
- export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/local/bin:/opt/local/sbin:"$HOME"/.local/bin:"$HOME"/.local/sbin
- logloc="/tmp/local.$(id -un).applaunched.log"
- exec > >(tee -a "$logloc") 2>&1
- currentdate=$(date)
- if ! [[ $* ]] ; then
- echo -e "*** APP LAUNCHED [$currentdate] ***\nERROR: no input!\n"
- exit
- fi
- bid=$(echo "$*" | awk -F" /" '{print $1}' | awk '{print $NF}')
- if ! [[ $bid ]] ; then
- echo -e "*** APP LAUNCHED [$currentdate] ***\nERROR: bundle ID missing!\n"
- exit
- fi
- _installer () {
- fullpkgpath=$(lsof -c Installer | grep "/.*pkg$" | awk '{print substr($0, index($0,$9))}' | sort | awk '!a[$0]++')
- if ! [[ $fullpkgpath ]] ; then
- echo -e "macOS Installer: no package detected! Exiting...\n"
- else
- pkgname=$(basename "$fullpkgpath")
- pkgloc=$(dirname "$fullpkgpath")
- echo -e "macOS Installer: $pkgname\nPath: $pkgloc"
- if pgrep -x "Suspicious Package" &>/dev/null ; then
- if lsof -c "Suspicious Package" | grep "$pkgname" &>/dev/null ; then
- echo -e "Package already opened in Suspicious Package: exiting...\n"
- osascript 2>/dev/null <<EOF
- tell application "System Events"
- tell application process "Suspicious Package"
- set frontmost to true
- end tell
- end tell
- EOF
- else
- echo -e "Opening in Suspicious Package...\n"
- open -a "Suspicious Package" "$fullpkgpath" 2>/dev/null &
- fi
- else
- echo -e "Opening in Suspicious Package...\n"
- open -a "Suspicious Package" "$fullpkgpath" 2>/dev/null &
- fi
- fi
- }
- read -d '' bundleids <<"EOB"
- com.apple.installer;_installer
- EOB
- rawcheck=$(echo "$bundleids" | grep "^$bid;" 2>/dev/null)
- if [[ $rawcheck ]] ; then
- procedure=$(echo "$rawcheck" | awk -F";" '{print $2}')
- echo -e "*** APP LAUNCHED [$currentdate] ***\n$bid"
- "$procedure"
- fi
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement