Yes. I do exactly this. There are MCWS commands that can launch the Handheld Sync. A few tips though:
I've found MC doesn't always fully calculate the changes in handheld syncs until you've quit and relaunched MC or opened the Handheld item in the Tree and viewed it onscreen. It always calculates it properly after being relaunched, but if you run it multiple times without closing and restarting MC "in between" you may not always get all of the changes you should. So, I've scripted MC to shut itself down and relaunch every night before running the sync.
Here's a VBS script that does that:
' glynor's MC-Quit_Relaunch_Server.vbs script
' ************************************************************************************************************
' ************************************************************************************************************
' PURPOSE: Quits and relaunches MC in Media Server Mode..
' ************************************************************************************************************
' RELEASE NOTES:
' ************************************************************************************************************
' 1.0.0 (2020-07-19)
' http://glynor.com/files/jriver/MC-Quit_Relaunch_Server.zip
' 1. Initial Release
'Create our handy dandy Shell object
set WshShell = WScript.CreateObject("WScript.Shell")
'Quit MC Entirely
WshShell.Run "MCcl.exe /Close"
'Wait a minute
WScript.Sleep 60000
'Relaunch MC in Media Server Mode
WshShell.Run "MCcl.exe /MediaServer"
Download:
http://glynor.com/files/jriver/MC-Quit_Relaunch_Server.zipEDIT: To be clear, it doesn't matter exactly when you exit and re-launch MC, so long as it happens at some point "between runs" of the sync job (and it may not be needed at all if your sync list is more manageable than mine). I have MC-Quit_Relaunch_Server.vbs set to run at 4am daily, and then my various different sync jobs at 4:30am (different ones on different days). Works perfectly.
Second, if your sync list is large (one of mine is 40k files) it can take a LONG time to do the initial sync calculation. You can trigger MC to automatically "recalculate the sync" by telling it to sync (and if it isn't ready, it'll get ready). But, if the recalculation takes too long, MCWS will reply back that the sync failed (but keep going recalculating). Therefore, when you script it, you'll probably want to have it run a few times (waiting in between) to get it to fully sync. The first try "fails" (but does the recalculation), and the second one actually runs the sync.
I have a script for this too. It runs the sync, checks to see if it fails or succeeded. If it failed, then it waits a configurable period of time and retries. You have to edit this one to point at your server, and then you run it with the /handheld option to specify which handheld in MC you want to sync.
' glynor's MC-Sync_Handheld.vbs script
' ************************************************************************************************************
' ************************************************************************************************************
' PURPOSE: Runs the specified Handheld sync in MC multiple times until it succeeds.
' REQUIRES: MC25
' MC must have Media Network enabled and a Username and Password set.
' USAGE: MC-Sync_Handheld.vbs /handheld:"Device Name"
' Optional Parameters:
' /verbosity:on - Asks for confirmation before continuing, and provides additional information.
' RETURNS: 0 if successful, 1 if failed
' ************************************************************************************************************
' RELEASE NOTES:
' ************************************************************************************************************
' 1.0.0 (2020-10-05)
' http://glynor.com/files/jriver/MC-Sync_Handheld.zip
' 1. Initial Release
' ************************************************************************************************************
' USER DEFINED VARIABLES
' ************************************************************************************************************
' You need to modify the items below to point at your MC Server.
const strServerAddress = "localhost:52199"
const strUsername = "username"
const strPassword = "password"
' This specifies the amount of time (in minutes) to wait between sync attempts.
const sleepBetweenAttempts = 10
' This specifies how many times to re-try the sync.
const maxAttempts = 3
' END USER DEFINED VARIABLES
' ************************************************************************************************************
' ************************************************************************************************************
' ALL USER DEFINED VARIABLES ARE ABOVE THIS LINE
' DON'T MODIFY ANYTHING BELOW HERE
' Info about this script
const strMyName = "MC-Sync_Handheld.vbs"
' Get command line arguments
dim colNamedArguments
dim strNewLibrary
set colNamedArguments = WScript.Arguments.Named
' Check for "/verbosity:on" argument
dim strVerbosity
if colNamedArguments.Exists("verbosity") then
' Assign the value to the strVerbosity variable and check to see if it's valid
strVerbosity = colNamedArguments.Item("verbosity")
if not (strVerbosity = "on" or strVerbosity = "off") then
ReportError strMyName & " ERROR:" & VbCrLf & VbCrLf & "/verbosity option given with invalid value. Available values are ""on"" or ""off"". Value given was: " & strVerbosity, 15, 1
end if
else
' Set strVerbosity to the default value of OFF
strVerbosity = "off"
'strVerbosity = "on" ' development mode
end if
' Check for "/handheld" argument
if colNamedArguments.Exists("handheld") then
' Assign the value to the targetFileType variable
strHandheldName = colNamedArguments.Item("handheld")
else
' Report the error and exit
ReportError strMyName & " ERROR:" & VbCrLf & VbCrLf & "/handheld option is required.", 0, 2
end if
' Set up the GET String
' Example:
' oXMLHTTP.open "GET", "http://" & strServerAddress & "/MCWS/v1/Handheld/Sync?Device=Wallpaper&DeviceType=Name&ShowWarnings=0", False, strUsername, strPassword
dim strUrl
strUrl = "http://" & strServerAddress & "/MCWS/v1/Handheld/Sync?Device=" & strHandheldName & "&DeviceType=Name&ShowWarnings=0"
' Set up re-attempt counter
dim attemptCount
do while attemptCount < maxAttempts
attemptCount = attemptCount + 1
' Do it, Doug!
dim result
set result = SendHttpGet
' Check results
if result.status = 200 then
if strVerbosity = "on" then ReportError strMyName & " Success!" & VbCrLf & VbCrLf & "URL: " & strUrl, 0, 0
WScript.quit 0
elseif result.status = 500 then
if attemptCount >= maxAttempts then ReportError strMyName & " FAILED Last Attempt: " & attemptCount & " (Max: " & maxAttempts & ")" & VbCrLf & VbCrLf & "URL: " & strUrl & VbCrLf & VbCrLf & "HTTP Status: " & result.status, 120, 500
ReportError strMyName & " FAILED Attempt: " & attemptCount & " (Max: " & maxAttempts & ")" & VbCrLf & VbCrLf & "URL: " & strUrl & VbCrLf & VbCrLf & "HTTP Status: " & result.status & VbCrLf & VbCrLf & "Retrying after " & sleepBetweenAttempts & " min delay...", 120, 0
WScript.Sleep sleepBetweenAttempts * 60000
else
ReportError strMyName & " FAILED:" & VbCrLf & VbCrLf & "URL: " & strUrl & VbCrLf & VbCrLf & "HTTP Status: " & result.status, 120, 1
end if
loop
function SendHttpGet
' This function actually sends the command and returns the result
dim oXMLHTTP
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
On Error Resume Next
oXMLHTTP.open "GET", strUrl, false, strUsername, strPassword
oXMLHTTP.send
' Report any errors
if Err.number <> 0 then
ReportError strMyName & " ERROR: " & Err.number & VbCrLf & VbCrLf & "Description: " & Err.Description, 120, Err.Number
end if
' Set the result
set SendHttpGet = oXMLHTTP
end function
sub ReportError (strErrorMessage, intTimeout, intFatalError)
' This procedure reports an error message to the user in a popup, with an timeout
' And can optionally end the script execution with a error code given.
' Usage:
' srtErrorMessage - The full text of the error message shown to the user
' intTimeout - auto-close the error message box after this many second (set to 0 to never close the box)
' intFatalError - if > 0 this will cause the script to stop executing, and return the given value as an error code
' Create our handy dandy Shell object
dim errWshShell
set errWshShell = WScript.CreateObject("WScript.Shell")
errWshShell.Popup strErrorMessage, intTimeout, , vbExclamation
if intFatalError > 0 then
WScript.quit intFatalError
end if
end sub
Download:
http://glynor.com/files/jriver/MC-Sync_Handheld.zipHope this helps!