Running a script after the gui has loaded

5,337

Solution 1

If you're going to launch something expensive, launch it in the background with a delay. For example

after 20s find-all-the-dirty-dishes &
after 1m find ~ -name '*~' -mtime +30 -exec rm '{}' ';'

where you will have to implement after yourself but it can be something like this

#!/bin/sh
sleep "$1"
shift
exec "$@"

Solution 2

Just call sleep at the beginning of your "nice-to-haves" script. That shouldn't block the desktop from loading. You may also be able to speed things up on multi-core hardware by backgrounding each process.

e.g.

sleep 20s
<something that takes a long time> &
<this can now start immediately> &
...

The two commands will run in parallel, but they'll wait for 20 seconds before starting. You can use "m", "h", or "d" to specify minutes, hours, or days if a few seconds isn't what you had in mind. =)

Share:
5,337

Related videos on Youtube

Satish
Author by

Satish

I'm the Solution Director Innovation for HCL Software, looking after an incredibly talented team of engineers based in Manila, Philippines. I hold multiple Salesforce certifications. Before that I worked in various roles: Salesforce Program Architect Director, IBM Code Mage for Collaboration &amp; Cloud in IBM ASEAN; NotesSensei for IBM Lotus Notes &amp; Domino, independent consultant and CTO for startups long before they became en vogue and venture backed. I started with COBOL (while studying economic, since there were no spreadsheets then), move to dBase and Foxpro. Fell in love with @1-2-3 and Lotus Agenda. Lotus Notes was the next logical step which I started with V2. I do JavaScript, Java &amp; VB.NET and XML and XSLT. My first mobile application ran on a Palm Pilot mobilising a SAP inventory system (that was already last century). I love the maker movement and got a cupboard full of electronics to tinker with. I live in Singapore. My core interests are knowledge management and eLearning. I'm a certified counselor for personcentric organisational development. And yes: plenty of Salesforce certs too. If you feel something is too complicated, chat with me, I'll explain it in simple terms.

Updated on September 18, 2022

Comments

  • Satish
    Satish over 1 year

    I know how to run a program on boot, on login (System > Preferences > Startup Applications) or on opening a shell (.bashrc). I also did read "execute script after desktop loaded?". What I realized that every application added to Startup Applications extends the time until the desktop becomes usable. So I'm looking for a way to start all the "nice to haves" from a script (got that working) that runs after the regular startup is finished.

    I'm not fully clear how to get there. Would I use a second script that calls the first one with & (so it runs in the background) and add a wait for (a few seconds|specific event) to the first one?

  • Satish
    Satish about 12 years
    Thx Jon. I guess that I would do in the startup apps: triggerNiceTohave.sh and inside triggerNicetohave.sh I do nicetohave.sh & and the sleep 20s is inside the nicetohave.sh?
  • Satish
    Satish about 12 years
    I tried that, but the startup seems to get delayed by it - very strange.
  • Norman Ramsey
    Norman Ramsey over 11 years
    You need something more complicated. Sleep is going to block startup for 20s.