Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Created November 19, 2023 18:48
Show Gist options
  • Save pdxmph/01987124fc62d96a62f42fb189528121 to your computer and use it in GitHub Desktop.
Save pdxmph/01987124fc62d96a62f42fb189528121 to your computer and use it in GitHub Desktop.
Wrapper to make nativifier apps and create the corresponding .desktop files
#!/usr/bin/env ruby
# - `makeapp.rb --help` for help on the options
require 'optparse'
# Where do we want to put things?
app_dir = "~/Applications"
custom_dir = "/home/mph/.local/share/applications/"
options = {}
OptionParser.new do |parser|
parser.on("-n", "--name NAME", "The name of the app.") do |o|
options[:name] = o
end
parser.on("-u", "--url URL", "The URL of the app") do |o|
options[:url] = o
end
parser.on("-i", "--internal INTERNAL_URLS", "URLs to be considered internal") do |o|
options[:internal_urls] = o
end
parser.on("-C", "--categories CATEGORIES", "semicolon-delimited list of categories") do |o|
options[:categories] = o
end
parser.on("-h", "--help", "Get help.") do
puts parser
exit(0)
end
end.parse!
file_path = File.expand_path(custom_dir + "#{options[:name]}.desktop")
desktop_file = <<~DESKTOP
[Desktop Entry]
# The type as listed above
Type=Application
# The version of the desktop entry specification to which this file complies
Version=1.0
# The name of the application
Name= #{options[:name]}
# A comment which can/will be used as a tooltip
Comment= #{options[:name]}
# The path to the folder in which the executable is run
Path= /home/mph/Applications/#{options[:name].capitalize}-linux-x64
# The executable of the application, possibly with arguments.
Exec= #{options[:name].capitalize}
# The name of the icon that will be used to display this entry
Icon= /home/mph/Applications/#{options[:name].capitalize}-linux-x64/resources/app/icon.png
# Desibes whether this application needs to be run in a terminal or not
Terminal=false
# Describes the categories in which this entry should be shown
#Categories=#{options[:categories]}
DESKTOP
`/usr/local/bin/nativefier #{options[:url]} #{app_dir} -n #{options[:name]}`
File.write(file_path, desktop_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment