Sample Header Ad - 728x90

Programmatically creating .desktop file to autostart application

1 vote
0 answers
2082 views
Using a Java program, I added a .desktop file in /etc/xdg/autostart to run a script when a user logs in. The script didn't run at user login, and when I checked the start up applications dialog manually, it wasn't added to it. The file I added is /etc/xdg/autostart/Startup.desktop, and the script I want to be run on user login is /usr/bin/Startscript. The code I wrote to add the desktop file is as follows: private void writeDesktopFile() { File f = new File("/etc/xdg/autostart/Startup.desktop"); if (!(f.exists())) { try { f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f, true)); bw.write("[Desktop Entry]"); bw.newLine(); bw.append("Name=Startup"); bw.newLine(); bw.append("Exec=Startscript"); bw.newLine(); bw.append("Type=Application"); bw.newLine(); bw.append("Terminal=false"); bw.newLine(); bw.append("Categories=GNOME;GTK;Utility;"); bw.newLine(); bw.append("X-Ubuntu-Gettext-Domain=Startscript"); bw.newLine(); bw.flush(); bw.close(); Runtime.getRuntime().exec("chmod +x /usr/bin/Startscript"); } catch (IOException ex) { Logger.getLogger(LinuxStartup.class.getName()) .log(Level.SEVERE, null, ex); } } Why isn't my script being run on start up?
Asked by Joker (161 rep)
Jul 1, 2014, 04:32 AM
Last activity: Jul 1, 2014, 12:41 PM