I use OneDrive in both Windows and GNU/Linux. To access/manage my files on OneDrive in GNU/Linux, I use a client I found on GitHub at onedrive-abraunegg. My distribution of choice (Solus) keeps the current version in the repository. Some distributions don’t do that, so if you want/decide to use it, check the docs/INSTALL.md page (linked in the onedrive-abraunegg landing page) to see if yours does. Setting up and using the client is covered in the docs/USAGE.md page, so I won’t cover all that here.
I dual-boot Solus GNU/Linux with Windows 11, and I switch between them a lot. I have been searching for a way to synchronize the files in my local OneDrive directory with OneDrive on the Internet when I log in. The onedrive-abraunegg client has a command to do that (onedrive --synchronize). I want to run that command when I log in as a regular user (not as an administrator). If you have one or more commands/applications you want to start/run when you log in, what follows may help.
First, I created a bash script (startup.sh) as follows:
#!/bin/bash
# Synchronize OneDrive at system start
onedrive --synchronize
echo "OneDrive synchronized: "$(date)>> ~/.config/onedrive/onedrive.log
echo >> ~/.config/onedrive/onedrive.log
exit
-
Tell the system this is a bash shell script.
-
Describe the intent of the following command.
-
Execute the 'onedrive --synchronize' command.
-
Output a text string containing the current date and time to a log file.
-
Exit
Second, I create a desktop launcher (Run startup commands.desktop) in ‘~/.config/autostart’ using the Dolphin file manager (I’m using KDE’s Plasma desktop environment).
- Navigate to ‘~/.config/autostart’ in Dolphin.
- ALT+Click an empty area in the directory’s main pane and select ‘Create New > Link to Application’.
- Give the desktop launcher a name in the top field (where it says ‘Link to application’ now).
- Switch to the ‘Application’ tab.
- Enter the same name in the ‘Name’ field.
- Optionally, you can enter a Description, Comment, and/or Environment Variables if needed/wanted.
- For the ‘Program’ field, I click ‘Browse’ and navigate to my ‘srartup.sh’ script, and select it.
- Click the ‘OK’ button to create the launcher.
Now, when I restart my computer to log into Solus, OneDrive is automatically synchronized for me, and a line containing the date and time of the synchronization is added to the ‘~/.config/onedrive/onedrive.log’ file.
You can create desktop launchers in the same way/location to start any application or run any command when you log in. I suggest you use a script file with a desktop launcher as I did to execute bash/terminal commands at startup, but create separate desktop launchers to run applications so you have more granular control over them.
UPDATE!!
I copied my Scripts directory and my ‘Run startup commands.desktop’ desktop launcher file from my primary laptop PC to OneDrive. I was able to use them on my desktop computer, which also dual-boots Windows 11 and Solus Linux with the Plasma DE. Even better, they also work as expected on my older Dell laptop PC, which dual-boots Windows 10 and Manjaro Linux with the xfce4 DE.
The only extra step needed to make everything work as expected (in both cases) was to run ‘chmod +x statartup.sh’ from the Scripts directory after copying everything to each computer. It’s my guess that this setting is stripped from the file when it’s stored on OneDrive (or possibly during the copy-paste operation?), or it’s not stored in the file itself, but in the file system.
Does anyone know how these permissions settings work under the hood/why they wouldn’t transfer from system to system as part of the file?
UPDATE January 13, 2024:
I discovered that my script runs at login, but the onedrive client isn’t synchronizing my local OneDrive file store with OneDrive in the cloud. After giving the issue some thought, I realized that my Internet connection doesn’t connect until I complete my login, so I inserted this command sleep 10
on the line before the onedrive --synchronize
command to make my script wait ten seconds before running the synchronization command, and my problem is solved. Interestingly enough, I don’t appear to need the sleep command in my new Solus-xfce system on my older Dell laptop computer. This makes me wonder what’s different between the two editions (xfce and Plasma) autostart implementation, or if it’s because my Dell laptop is slower than my desktop and primary laptop computers.
I hope others find this useful,
Ernie