Skip to content

Commit

Permalink
Bug Fixing and rewrite part of the script
Browse files Browse the repository at this point in the history
  • Loading branch information
Piero24 committed Nov 3, 2023
1 parent 86229da commit 6a6d2ef
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 254 deletions.
46 changes: 23 additions & 23 deletions PNPMacInstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if [ ! -e "/usr/local/bin/PlugNPlayMac/bclm" ]; then
# echo "Selected Display: $selectedDisplay"

newVariable="listDisplayNames=(${selectedDisplay} )"
sed -i '' -e "/^listDisplayNames=/s/.*/$newVariable/" ./PNPMacParam.sh
sed -i '' -e "/^listDisplayNames=/s/.*/$newVariable/" ./PlugNPlayMac/PNPMacParam.sh

clear

Expand Down Expand Up @@ -119,7 +119,7 @@ if [ ! -e "/usr/local/bin/PlugNPlayMac/bclm" ]; then
# sed -i '' -e "/^listWifiNames=/s/.*/$newVariable/" ./PNPMacParam.sh

newVariable="listWifiNames=(${selectedWifi} )"
sed -i '' -e "/^listWifiNames=/s/.*/$newVariable/" ./PNPMacParam.sh
sed -i '' -e "/^listWifiNames=/s/.*/$newVariable/" ./PlugNPlayMac/PNPMacParam.sh

clear

Expand All @@ -145,7 +145,7 @@ if [ ! -e "/usr/local/bin/PlugNPlayMac/bclm" ]; then
fi
done

sed -i '' -e "/^listAppToOpen=/s/.*/$selectedApp/" ./PNPMacParam.sh
sed -i '' -e "/^listAppToOpen=/s/.*/$selectedApp/" ./PlugNPlayMac/PNPMacParam.sh

clear

Expand Down Expand Up @@ -176,7 +176,7 @@ if [ ! -e "/usr/local/bin/PlugNPlayMac/bclm" ]; then
# echo "Selected Battery Value: $selectedBatteryValue"

newVariable="batteryValue=${selectedBatteryValue}"
sed -i '' -e "/^batteryValue=/s/.*/$newVariable/" ./PNPMacParam.sh
sed -i '' -e "/^batteryValue=/s/.*/$newVariable/" ./PlugNPlayMac/PNPMacParam.sh

#
# Start coping the files
Expand All @@ -191,19 +191,19 @@ if [ ! -e "/usr/local/bin/PlugNPlayMac/bclm" ]; then
fi

# Move files to /usr/local/bin/PlugNPlayMac
sudo mv PlugNPlayMac.sh /usr/local/bin/PlugNPlayMac
sudo mv ./PlugNPlayMac/PlugNPlayMac.sh /usr/local/bin/PlugNPlayMac
if [ $? -ne 0 ]; then
display_error "Error moving PlugNPlayMac.sh"
exit 1
fi

sudo mv PNPMacParam.sh /usr/local/bin/PlugNPlayMac
sudo mv ./PlugNPlayMac/PNPMacParam.sh /usr/local/bin/PlugNPlayMac
if [ $? -ne 0 ]; then
display_error "Error moving PNPMacParam.sh"
exit 1
fi

sudo mv bclm /usr/local/bin/PlugNPlayMac
sudo mv ./PlugNPlayMac/bclm /usr/local/bin/PlugNPlayMac
if [ $? -ne 0 ]; then
display_error "Error moving bclm"
exit 1
Expand Down Expand Up @@ -232,14 +232,14 @@ if [ ! -e "/usr/local/bin/PlugNPlayMac/com.launch.plug.and.play.mac.plist" ]; th
fi

# Copy the plist file to /Library/LaunchAgents
sudo cp com.launch.plug.and.play.mac.plist /Library/LaunchAgents
sudo cp ./PlugNPlayMac/com.launch.plug.and.play.mac.plist /Library/LaunchAgents
if [ $? -ne 0 ]; then
display_error "Error copying com.launch.plug.and.play.mac.plist"
exit 1
fi

# Move the plist file to /usr/local/bin/PlugNPlayMac
sudo mv com.launch.plug.and.play.mac.plist /usr/local/bin/PlugNPlayMac
sudo mv ./PlugNPlayMac/com.launch.plug.and.play.mac.plist /usr/local/bin/PlugNPlayMac
if [ $? -ne 0 ]; then
display_error "Error moving com.launch.plug.and.play.mac.plist"
exit 1
Expand All @@ -259,20 +259,20 @@ if [ ! -e "/usr/local/bin/PlugNPlayMac/com.launch.plug.and.play.mac.plist" ]; th
\n"

else

# Define the path to the shell script
shell_script="/usr/local/bin/PlugNPlayMac/PlugNPlayMac.sh"

# Check if the script exists and is executable
if [ -x "$shell_script" ]; then
# Start the shell script
bash "$shell_script"
else
display_error "The shell script '$shell_script' does not exist or is not executable."
exit 1
fi

pkill caffeinate
# # Define the path to the shell script
# shell_script="/usr/local/bin/PlugNPlayMac/PlugNPlayMac.sh"

# # Check if the script exists and is executable
# if [ -x "$shell_script" ]; then
# # Start the shell script
# bash "$shell_script"
# else
# display_error "The shell script '$shell_script' does not exist or is not executable."
# exit 1
# fi

# pkill caffeinate
launchctl load /Library/LaunchAgents/com.launch.plug.and.play.mac.plist

echo "Done."
Expand Down
35 changes: 25 additions & 10 deletions PNPMacParam.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ isCaffeinate=false
isBclm=false
# Apps
areAppsOpen=false
# Get the full name of the user
accountUser=$(getUSR)

# ID of the last active caffeinate process (0 at start of the script)
PMSETPID=0
# main directory
Expand All @@ -40,6 +39,17 @@ parentPath=/usr/local/bin/PlugNPlayMac
notFoundedApp=()


getUSR() {
# Take the full name of the user

local my_var
my_var=$(id -F)
echo "$my_var"
}

# Get the full name of the user
accountUser=$(getUSR)

getPW() {
# Take the password from Apple Keychain for operating the sudo operation

Expand All @@ -54,14 +64,6 @@ getPW() {
echo "$my_var"
}

getUSR() {
# Take the full name of the user

local my_var
my_var=$(id -F)
echo "$my_var"
}

detect_cpu_architecture() {

architecture=$(uname -m)
Expand All @@ -79,3 +81,16 @@ detect_cpu_architecture() {

echo "$my_var"
}

log_error() {
local msg_type="$1"
local isAppleSilicon="$2"
local msg_text="$3"
local date_string=$(date +"%b %d %Y - %H:%M")

if [ -n "$isAppleSilicon" ]; then
echo "$date_string: (I$msg_type): $msg_text"
else
echo "$date_string: (A$msg_type): $msg_text"
fi
}
73 changes: 0 additions & 73 deletions PNPMacParam2.sh

This file was deleted.

Loading

0 comments on commit 6a6d2ef

Please sign in to comment.