Here's a working example of a script that runs when NetworkManager connects:
#!/bin/sh -e
# Script to dispatch NetworkManager events
#
# Runs ifupdown scripts when NetworkManager fiddles with interfaces.
# See NetworkManager(8) for further documentation of the dispatcher events.
if [ -z "$1" ]; then
echo "$0: called with no interface" 1>&2
exit 1;
fi
# Run the right scripts
case "$2" in
up|vpn-up)
logger -s "HELLO THIS IS YOUR SCRIPT"
cd /home && touch "HELLOFILE.txt"
;;
down|vpn-down)
;;
hostname|dhcp4-change|dhcp6-change)
# Do nothing
;;
*)
echo "$0: called with unknown action \`$2'" 1>&2
exit 1
;;
esac
Name the script above anything you like, make it executable, and put it into the /etc/NetworkManager/dispatcher.d/
directory.
You can verify that this works by opening a terminal and running:
sudo tail -f /var/log/syslog
//print system log until cancelled
Then open another terminal, and run:
sudo service network-manager restart
//restart NetworkManager
You should see the words "HELLO THIS IS YOUR SCRIPT" appear in the log, with a lot of other info. And the file should be added to the /home
directory.
I'm not sure why your specific case of opening gedit isn't working, but this is the way to run a script when network manager starts. My guess is that the rest of the problem is related to the fact that the script runs as root but you're wanting gedit to open in the desktop environment of a specific user (you). Good luck!