LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 07-02-2023, 04:36 PM   #1
edcompsci
LQ Newbie
 
Registered: Jul 2012
Posts: 16

Rep: Reputation: Disabled
just sharing this script I made that creates a desktop shortcut to webpage


Code:
#!/bin/bash
#choose directory to put file
echo "directory"
read directory
#Choose attributes
echo "Encoding"
read encode   #example UTF-8
echo "Name"
read name		#example Course
iconfile="$name.desktop"  
echo "file will called be called $iconfile and put into the $directory directory."
echo "Type (Application for weblink)"
read type		#example link
echo "weblink"
read weblink		#example https://randomprojectgenerator.com/
#echo "filepath url" #example /home
#read url
echo "icon"
read icon		#example text-html

# move to chosen directory
if [ $directory = "~" ]
then
  cd ~
  directory=$(pwd)
else
  cd $directory
fi

#create file
touch $iconfile

#populate file
echo "[Desktop Entry]" > $iconfile
echo "Encoding=$encode" >> $iconfile
echo "Name=$name" >> $iconfile
echo "Type=$type" >> $iconfile
echo "Exec=firefox $weblink" >> $iconfile
echo "Icon=$icon" >> $iconfile
 
Old 07-02-2023, 06:00 PM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,426
Blog Entries: 7

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Code:
#!/bin/bash

read -p "Enter directory: " directory
read -p "Choose encoding (ex UTF-8): " encode
read -p "Enter name: " name

iconfile=""$name".desktop"

echo "File is "$iconfile", Directory is "$directory""

read -p "Type (Application for weblink): " type
read -p "Enter weblink: " weblink
read -p "Enter icon: " icon

if [ $directory = "$HOME" ]; then
    cd $HOME
    directory=$(pwd)
else
    cd "$directory"
fi

echo -e "[Desktop Entry]\nEncoding="$encode"\nName="$name" \
Type="$type"\nExec=firefox "$weblink"\nIcon="$icon"" > "$iconfile"
 
1 members found this post helpful.
Old 07-03-2023, 12:51 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,316

Rep: Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985Reputation: 7985
Code:
directory=$(readlink -f $directory)
cd $directory
Otherwise error handling is missing, how will it work with invalid/incorrect/missing input values?
 
1 members found this post helpful.
Old 07-03-2023, 08:42 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,932

Rep: Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808Reputation: 2808

The following script was run through Shellcheck before posting - to verify I didn't slip up with regards to quoting...

Code:
#!/bin/bash

read -rep "Name: " name
read -rep "Directory: " -i "$HOME" directory
read -rep "Encoding: " -i "UTF-8" encoding
read -rep "Type: " -i "link" type
read -rep "Weblink: " -i "https://" weblink
read -rep "Icon: " -i "text-html" icon

directory=$(readlink -f "$directory")

iconfile="$directory/$name.desktop"

# TODO: insert validation and confirmation

echo "Creating file [$iconfile]"

cat > "$iconfile" <<-eof
	[Desktop Entry]
	Encoding=$encoding
	Name=$name
	Type=$type
	Exec=firefox $weblink
	Icon=$icon
eof
To understand specifics, one may wish to consult "help read" (or the read command in Bash manual), man readlink, and Here Documents in the Bash manual.

Validation is left as an exercise to the reader, but it is an important step - not just to check values are correct, but also because it would be annoying to unintentionally enter a non-unique name and overwrite an existing file...

 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I made a global shortcut to block an unwanted in-application shortcut newbiesforever LinuxQuestions.org Member Success Stories 0 07-22-2018 07:49 PM
Webpage input that creates Lead in back end ASP.NET server vondie Programming 5 09-04-2009 04:39 PM
webpage in webpage? kalleanka Programming 6 06-07-2009 04:13 PM
LXer: Piracy creates jobs, FOSS creates opportunities LXer Syndicated Linux News 0 11-02-2006 11:33 AM
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 11:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration