Choose style:

Author Topic: Start a shell script at startup  (Read 869 times)

0 Members and 1 Guest are viewing this topic.

Offline Fritz74

  • Member
  • ***
  • Posts: 103
  • Karma: 11
  • m, 45, Austria
    • View Profile
  • Peppermint version(s): 10
Start a shell script at startup
« on: October 25, 2017, 08:17:10 am »
This is the next step in my pursuit to have < and > instead of CapsLock. Yesterday PCNetSpec told me the command. Thanks again! I admire your knowledge and your willingness to help. :)

Now I want this command to run at every start of the machine. This seems to be (a lot) less trivial than I expected.

I put the command in a shell script in my /home-folder and named it capslocker.sh:
Code: [Select]
#!/bin/sh

setxkbmap -option caps:none && xmodmap -e "keycode 66 Shift = less greater"
I made it executable and tested it from the command line.

Then I created a file named capslocker.service in /etc/systemd/system/ with the following content:
Code: [Select]
[Unit]
Description=Change CapsLock behavior

[Service]
Type=oneshot
ExecStart=/bin/sh /home/friedrich/capslocker.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
I enabled it with: sudo systemctl enable capslocker
Then I tried to run it with: sudo systemctl start capslocker

systemctl status capslocker.service displayed the following output:
Quote
capslocker.service - Change CapsLock behavior
   Loaded: loaded (/etc/systemd/system/capslocker.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mit 2017-10-25 14:12:49 CEST; 22s ago
  Process: 6473 ExecStart=/bin/sh /home/friedrich/capslocker.sh (code=exited, status=255)
 Main PID: 6473 (code=exited, status=255)

Okt 25 14:12:49 friedrich-NA123 systemd[1]: Starting Change CapsLock behavior...
Okt 25 14:12:49 friedrich-NA123 sh[6473]: Cannot open display "default display"
Okt 25 14:12:49 friedrich-NA123 systemd[1]: capslocker.service: Main process exited, code=exited, status=255/n/a
Okt 25 14:12:49 friedrich-NA123 systemd[1]: Failed to start Change CapsLock behavior.
Okt 25 14:12:49 friedrich-NA123 systemd[1]: capslocker.service: Unit entered failed state.
Okt 25 14:12:49 friedrich-NA123 systemd[1]: capslocker.service: Failed with result 'exit-code'.
~
~
Where is the mistake?





« Last Edit: October 29, 2017, 10:49:28 am by Fritz74 »

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25659
  • Karma: 2819
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: Start a shell script with system.d
« Reply #1 on: October 25, 2017, 09:45:09 am »
Don't start it as it as a systemd service, without some tweaking it'll likely be run as the wrong user and too early.. you're going to want to run it as two separate components.

a) To disable the capslock

Run:
Code: [Select]
pluma ~/.capslock-disable.sh
when a blank file opens, make it read:
Code: [Select]
#!/bin/sh

setxkbmap -option caps:none
SAVE the file and exit the text editor.

Back in the terminal make it executable with:
Code: [Select]
chmod +x ~/.capslock-disable.sh
Okay lest's autostart that...

menu > Preferences > Default applications for LXSession > Autostart (tab)

Then in the "Manually autostarted applications" box enter:
Code: [Select]
/home/Fritz74/.capslock-disable.sh
(obviously changing the path to your script if your username isn't Fritz74)
and click the "Add" button.


b) To run the xmodmap part of the command

Run:
Code: [Select]
pluma ~/.Xmodmap
add this line:
Code: [Select]
keycode 66 Shift = less greater
SAVE the file and exit the text editor.

Reboot to test.
« Last Edit: October 25, 2017, 04:05:34 pm by PCNetSpec »
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline Fritz74

  • Member
  • ***
  • Posts: 103
  • Karma: 11
  • m, 45, Austria
    • View Profile
  • Peppermint version(s): 10
Re: Start a shell script with system.d
« Reply #2 on: October 25, 2017, 09:49:34 am »
Perfect! Thank you.  :)