kingoslo
Posts: 20
Joined: Sun Nov 18, 2012 11:21 pm

How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 3:38 pm

Hello there,

I would like to:

Code: Select all

$ okular /path/to/file.pdf --presentation
This line launches the app named okular in presentation mode (typical slideshow format). I want this to happen automatically every time OS boots.

Somebody suggested I make a sh-script with this exact line of code in it, and add "/path/to/script.sh" into /etc/rc.local. I did this, but the app does not launch after startup at all.

How should I proceed?

Thank you for your time.

Kind regards,
Marius

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 3:49 pm

You might need to have the full path to okular in /etc/rc.local, i.e.

Code: Select all

/usr/bin/okular /path/to/file.pdf --presentation &

kingoslo
Posts: 20
Joined: Sun Nov 18, 2012 11:21 pm

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 4:08 pm

Ok, so this is what I did.

I made one file /home/pi/present.sh. All it contains is:

Code: Select all

#! /bin/bash
/usr/bin/okular beamer.pdf --presentation &
This is the entire contents of rc.local:

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address

/home/pi/present.sh

_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

exit 0
It does still not launch okular after startup.

Kind regards,
Marius

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 4:18 pm

Have you made the script executable?

chmod +x /home/pi/present.sh

kingoslo
Posts: 20
Joined: Sun Nov 18, 2012 11:21 pm

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 4:24 pm

joan wrote:Have you made the script executable?

chmod +x /home/pi/present.sh
Yes I did.

What do you think?

Thanks.M

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 4:27 pm

I've no idea. What you have done should work.

What happens if you type

/home/pi/present.sh

kingoslo
Posts: 20
Joined: Sun Nov 18, 2012 11:21 pm

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 4:34 pm

joan wrote:I've no idea. What you have done should work.

What happens if you type

/home/pi/present.sh

Typing this into the terminal launches okular.

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 4:38 pm

Perhaps your variant of Linux doesn't use /etc/rc.local. I'm fairly sure the Debian based distributions do use /etc/rc.local. Which distribution are you using?

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 4:38 pm

Okular is a X-windows application right ?

rc.local is probably run before x-windows starts. You'll have to wait until both X and your window-manager is started to start Okular.

I assume that you have enabled the x-windows desktop and made so the user "pi" is automatically logged in.

Read this for tips on having LXDE start your application. (the wiki is for Archlinux but I assume LXDE behaves similar on debian/raspbian)
https://wiki.archlinux.org/index.php/LX ... t_programs

kingoslo
Posts: 20
Joined: Sun Nov 18, 2012 11:21 pm

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 5:06 pm

Not sure what x-windows app is, but perhaps this answers the question: okular is an app with a GUI, just like Midori. Yes I believe this is the reason it isn't working.

I read the document which you recommended. Under the sub-heading autostart file, the author refers to "~/.config/lxsession/LXDE/autostart". -- The first problem is that I am unable to find the directory lxsession.

Second, I do not understand any of what is written under the sub-heading .desktop files. Never heard of any of that, so unfortunately it makes no sense to me :cry:

This is what I am keen to do: I think it could be best to find a way to launch a script after all of the required stuff has been started, that way I could not only start okular, but start okular in display mode using this line:

Code: Select all

$ okular /path/to/file.pdf --presentation
How can I do that?

Thank you for your time.

Kind regards,
Marius

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 5:34 pm

If you type "autostart" in the search box in the top right corner you will find other threads on this subject.

This is one:
http://www.raspberrypi.org/phpBB3/viewt ... rt#p395147

kingoslo
Posts: 20
Joined: Sun Nov 18, 2012 11:21 pm

Re: How to automatically exec startup command after OS boot?

Sun Aug 18, 2013 7:21 pm

topguy wrote:If you type "autostart" in the search box in the top right corner you will find other threads on this subject.

This is one:
http://www.raspberrypi.org/phpBB3/viewt ... rt#p395147

That worked!

Takk kompis.M

Return to “Beginners”