-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesktopFileCreator.java
More file actions
54 lines (44 loc) · 2.04 KB
/
DesktopFileCreator.java
File metadata and controls
54 lines (44 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.company;/*
Title: This creates a .desktop file in java
Author: Riley Carpenter
TODO: Make the program able to move the .desktop file to ~/.local/share/applications
*/
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Main {
//Creates the File
public static void createDesktopFile(String fileName, String exe, String ico) throws IOException {
List<String> lines = Arrays.asList("[Desktop Entry]", "Encoding=UTF-8","Version=1.0","Type=Application","Terminal=false","Exec=" +exe,"Name=" +fileName,"Icon=" + ico);
Path file = Paths.get(System.getProperty( "user.home" ) + "/.local/share/applications/" + fileName + ".desktop");
//Sets File's Permissions
Set<PosixFilePermission> ownerWritable = PosixFilePermissions.fromString("rw-r--r--");
FileAttribute<?> permissions = PosixFilePermissions.asFileAttribute(ownerWritable);
Files.createFile(file, permissions);
Files.write(file, lines, Charset.forName("UTF-8"));
}
//Main method
public static void main(String[] args) throws IOException{
Scanner reader = new Scanner(System.in);
System.out.print("What is the name of the executable? ");
String fileName = reader.nextLine();
System.out.print("What is the file path for the executable? ");
String executableFile = reader.nextLine();
System.out.print("What is the icon path for the file? (Leave blank if none) ");
String iconPath = reader.nextLine();
reader.close();
createDesktopFile(fileName, executableFile, iconPath);
System.out.print("\u001b[2J");
System.out.flush();
System.out.println("Desktop File Created Successfully!");
}
}