[Gambas-user] Automatic Startup

Bruce Steers bsteers4 at gmail.com
Fri Nov 4 03:56:18 CET 2022


Hey Gian, I use the following bash script with some of my applications to
compile without the IDE...
It offers to compile the exe and optionally make a desktop icon.

It is run from the project folder and makes the exe there (and the desktop
icon will use the same location)

it uses gbc3 and gba3 to compile so they need to be installed and of course
the components required for the application. not the IDE
(it also uses zenity for Messages)

it takes into account PublicModule and PublicControl options (handles old
and new method to pass the options to the compiler)
it also passes -wax flags

Maybe what you need.
Unless you need "AutoStart" (if so, read below)

----------------------------------------------
#!/usr/bin/env bash

# Get application directory and name
WD=${0%/*}
AppName=${WD##*/}

source $HOME/.config/user-dirs.dirs
DESK=$XDG_DESKTOP_DIR

REP=$(zenity --question --width=400 --extra-button='Just Compile'
--cancel-label="Abort" --ok-label="Do it" --text="Compile $AppName.gambas
in...\n$WD\n\nThen create a Desktop Launcher in...\n$XDG_DESKTOP_DIR
?\n\n(Launcher will run $AppName from this location)")
ERR=$?

if [ -z "$REP" ]; then
  if [ $ERR -eq 1 ]; then exit; fi
fi

cd "$WD"

ControlPublic=0
ModulePublic=0
eval $(cat .project|grep Public)

KeepDebugInfo=1
eval $(cat .project|grep KeepDebugInfo)

echo "Compiling gambas executable..."
FLG="-wax"
MODE="-f"
CHK=$(gbc3 --help| grep public-module| awk {'print $1'})
if [[ $CHK != "-f" ]]; then
MODE="-"
fi
if [ $KeepDebugInfo -eq 1 ]; then FLG="$FLG"g; fi
if [ $ControlPublic -eq 1 ]; then FLG="$FLG "$MODE"public-control"; fi
if [ $ModulePublic -eq 1 ]; then FLG="$FLG "$MODE"public-module"; fi

gbc3 $FLG
gba3

if [ $ERR -eq 1 ]; then exit; fi

echo "Making launcher..."

# try to get icon from .project file or use default
IC=$(cat "$WD/.project" |grep Icon=)

if [ -z "$IC" ]; then Icon=".icon.png"; else Icon=${IC##*=}; fi

echo "[Desktop Entry]
Type=Application
Name=$AppName
Icon=$WD/$Icon
Exec=$WD/$AppName.gambas" >"$XDG_DESKTOP_DIR/$AppName.desktop"

chmod +x "$XDG_DESKTOP_DIR/$AppName.desktop"

zenity --info --width=400 --text="All Done,
$XDG_DESKTOP_DIR/$AppName.desktop created."
----------------------------------


But that is to compile without IDE not "Autostart"

Here's my gambas code for making an application auto-start at computer boot
up...
IsAutoStarted(True) tests if autostart is available (probably) should work
for mate/gnome/kde, possibly others
MNU_Startup_Click() is a toggle menu to toggle autostart.

-------------------------------

Public Sub IsAutoStarted(Optional bTest As Boolean) As Boolean

  If Not AutoStartFile Then
    AutoStartFolder = User.Home &/ If(GetDesktop() Like "KDE*",
".kde/Autostart", ".config/autostart")
    AutoStartFile = File.Name(Args[0])
    If File.Ext(AutoStartFile) <> "gambas" Then AutoStartFile &= ".gambas"
    AutoStartFile &= ".desktop"
  Endif

  If bTest Then Return Exist(AutoStartFolder)

  Return Exist(AutoStartFolder &/ AutoStartFile)

End

Public Sub MNU_Startup_Click()

  If Not IsAutoStarted(True) Then Error.Raise("Cannot set AutoStart")

  If Last.Value Then
    Dim sMe As String = Application.Path &/ File.Name(Args[0])
    If File.Ext(sMe) <> "gambas" Then sMe &= ".gambas"

    Dim sData As String = "[Desktop Entry]\nType=Application\nExec="
    sData &= sMe & "\nHidden=false\nName=" & Application.Name
    sData &=
"\nX-MATE-Autostart-enabled=true\nX-MATE-Autostart-Delay=5\nX-GNOME-Autostart-Delay=5"
    File.Save(AutoStartFolder &/ AutoStartFile, sData)
  Else
    Kill AutoStartFolder &/ AutoStartFile
  Endif

Catch
  Message.Error("Error!\n" & Error.Text)

End

-------------------------

Best of luck
BruceS


On Thu, 3 Nov 2022 at 22:53, gian via User <user at lists.gambas-basic.org>
wrote:

> Hi Benoit,
>
> my wife wanted to have on her desktop, a clock (type alarm clock), as
> simple as the one she has on her nightstand, but nice as an day-date
> clock, with the moon phase, and that started automatically with the
> Linux session.
>
> On the Farm named mdDDclock (moon phase Day Date clock) is the result of
> my work.
>
> It can only work if the Gambas IDE is installed (it have to run an
> executable).
>
> Is there any way to create a project that starts automatically without
> having to install the IDE ?
>
> Thank you and regards
>
> Gianluigi
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20221104/683b94d4/attachment-0001.htm>


More information about the User mailing list