I'm using Rclone to mount/unmount Google Drive. I don't need it to run constantly in the background so I want to be able to mount/unmount it as needed.
Currently, I created two separate buttons for mounting and unmounting GDrive. However, I was wondering if this be made more efficient by combining them into a single toggle button that will mount/unmount GDrive with every click.
The current commands are: Mounting rclone mount GDrive: G:
Unmounting taskkill /im rclone.exe /f
I search through the forum and found some examples for toggling a view, setting/removing a label from a file, but I struggle to apply the code to what I hope to achieve. I'd appreciate any hint.
And a quick follow up question, is there a way to run a batch command through an Opus button without opening the console window? When I run rclone mount GDrive: G:, a console window opens and remains open as long as Rclone is running.
I managed to run the command silently in the background using the following VB script, but it seems Opus doesn't support WSH and therefore doesn't recognize WScript.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c rclone mount GDrive: G:", 0, False
Set WshShell = Nothing
I can always run the VBS file directly through the a button in Opus, but I prefer to run the command directly, if possible.
I want to highlight the button when GDrive is mounted and thought I could use the @toggle command for this. However, based on the documentation, it seems to apply only to filters. Is there another way to achieve this?
Ultimately, I want to change the icon depending on the state, which I understand can now be done in v13 using the eval command but in the meantime while I'm looking into this I thought of using the button highlight state as an indicator.
Another issue I encountered is that it takes a second or two for the remote drive to mount or unmount. Consequently, when I view "This PC," the drive appears as mounted or unmounted until I refresh.
I tried adding Go REFRESH=source after each command and then only after the unmounting command, but this caused the button to stop working. Adding Go REFRESH=source only at the end of the script seems to work, but only after a mount.
My primary concern is having the state refreshed after an unmount since it is both a more immediate action and important as I want to confirm the drive has unmounted.
For mounting, it takes 1-3 seconds anyway, so an immediate refresh doesn't help much without adding a delay and I prefer not to use arbitrary delays in scripts.
One would indeed think so and that an umount command would be available, but as it turns out, this is the only and somewhat recommended way to stop rclone in Windows.
I always give it a couple of good seconds between the end of a file operation and "unmounting" GDrive, and users who use this method claim they haven't run into into data corruption issues using this method.
For reference, this is the button code I've currently ended up with. I'm using the nircmd tool until I'll figure out how to run rclone without the console windows using Opus' VB script (as it doesn't recognize WScript):
@toggle:=Exists("G:")
@ifexists:G:
C:\Users\Shai\Applications\Nirsoft\Nircmd\nircmd.exe killprocess rclone.exe
Go REFRESH=source
@ifexists:else
C:\Users\Shai\Applications\Nirsoft\Nircmd\nircmd.exe exec hide rclone mount GoogleDrive: G: