Advertisement
winhelponline

Windows Spotlight wallpaper collector

Oct 3rd, 2020
2,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Copies Spotlight images from Assets folder to "Pictures\Spotlight Collections"
  2. 'Picks up only the Landscape images, and having size >250KB.
  3. 'For Windows 10 systems. Can run as a scheduled task as well.
  4. 'Feel free to modify the script as you need.
  5.  
  6. Option Explicit
  7. Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
  8. Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
  9. Dim objFolder, oPic
  10. Dim strAssetsFldr, strSpotlightFldr
  11.  
  12. Const MY_PICTURES = &H27&
  13. Dim objShell2: Set objShell2 = CreateObject("Shell.Application")
  14. Dim objFolder2: Set objFolder2 = objShell2.Namespace(MY_PICTURES)
  15. Dim objFolderItem: Set objFolderItem = objFolder2.Self
  16.  
  17. strAssetsFldr = WshShell.ExpandEnvironmentStrings("%localappdata%") & _
  18. "\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
  19.  
  20. 'strSpotlightFldr = WshShell.ExpandEnvironmentStrings("%userprofile%") & _
  21. '"\Pictures\Spotlight Collection"
  22.  
  23. strSpotlightFldr = objFolderItem.Path & "\Spotlight Collection"
  24.  
  25. If Not objFSO.FolderExists (strSpotlightFldr) Then objFSO.CreateFolder strSpotlightFldr
  26. strSpotlightFldr = strSpotlightFldr & "\"
  27.  
  28. If objFSO.FolderExists (strAssetsFldr) Then  
  29.    Set objFolder = objFSO.GetFolder(strAssetsFldr)  
  30.    Dim file, iHeight, iWidth
  31.    For Each file In objFolder.Files
  32.       If objFSO.FileExists(strSpotlightFldr & file.Name & ".jpg") <> True _
  33.          And LCase(file.Name) <> "thumbs.db" Then
  34.          If file.Size > 250000 Then
  35.             On Error Resume Next
  36.             Set oPic = LoadPicture(file)
  37.             'Skip pictures that can't be loaded
  38.            If err.number = 0 Then
  39.                iWidth = CInt(round(oPic.width / 26.4583))
  40.                iHeight = CInt(round(oPic.height / 26.4583))
  41.                'Lets copy only Landscape images of size >250KB
  42.               If iHeight < iWidth Then
  43.                   objFSO.CopyFile file, strSpotlightFldr & file.name & ".jpg", False
  44.                   If err.number <> 0 And err.number <> 58 Then
  45.                      WScript.Echo err.number & vbCrLf & err.Description
  46.                   End If
  47.                End If
  48.             End If
  49.             On Error GoTo 0
  50.          End If
  51.       End If
  52.    Next
  53. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement