shell脚本设置Mac电脑desktop picture

#!/bin/bash
#设置desktop picture
#desktop.png为desktop picture,username为计算机名
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/username/Pictures/desktop.png"'

bat脚本设置Windows电脑desktop picture
注:必须以管理员身份运行

@echo off
reg add "hkcu\control panel\desktop" /v "wallpaper" /d "图片路径" /f
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters

Powershell自动更换壁纸的函数方法

保存如下代码到一个.ps1文件中。(可以用记事本编辑再更改文件拓展名)

Function Set-WallPaper($Value)
{
 Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
 rundll32.exe user32.dll, UpdatePerUserSystemParameters 1, True
}

Set-WallPaper -value "C:\Windows\Web\Wallpaper\Homes_Background.bmp"

将其中C:\Windows\Web\Wallpaper\Homes_Background.bmp更改成壁纸所在处,执行脚本即生效。

windows打开屏幕保护程序脚本

rundll32.exe desk.cpl,InstallScreenSaver toasters.scr

mac打开屏幕保护程序脚本(未验证)

#!/bin/sh
#  above line specifies which shell to useto execute this file
#  author: rob stone.  psychology, university of york, uk. modified by
#  idea from foon (Joel Kraut) on  mscosxhints see
#  http://www.macosxhints.com/article.php?story=20020830050630964

#set -x
#debugging switch - uncomment to see what is happening

#shell variables set in one place for ease
PATH=/bin:/sbin:/usr/bin:/usr/sbin  # set to make sure nothing odd gets run
SAVER="/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine "
USER=`users`

NICE="nice -n 20 "        # run at a lower priority so as to free up resources
BKG=0                     # set to 1 if you always wnat this and you can alter the behaviour of -b
SWITCHES=" -background "  # set to run in the background,

function usage () {
# show the usage info with the options
    PROGNAME=`basename $0` ;
    echo "Usage: $0  [-d|-h|-k|-l]  [-b] [-f] [-r|-m modname]"
    echo "  $PROGNAME       use currently chosen module"
    echo "  $PROGNAME -b    background the task (&) and return control to terminal"
    echo "  $PROGNAME -d    display all the running screensaver modules and exit"
    echo "  $PROGNAME -f    display in the foreground - funky"
    echo "  $PROGNAME -h    show this help screen and exit"
    echo "  $PROGNAME -k    kill all the running screensavers and exit"
    echo "  $PROGNAME -l    list available modules for $USER and system and exit"
    echo "  $PROGNAME -m modname use module Modname"
    echo "  $PROGNAME -r    use the Random module"
    echo
    echo "Note: specifing more than one -r or -m will use the last one listed"
    echo
    exit 0 
}   


function killsavers() {
# get the ps lines for very occurence  the pid is the first 5 chars
    for ID in `ps -c | fgrep "ScreenSaverEn" | cut  -c1-5  `
    do
        kill $ID
    done
}  

# loop around the flags processong each one.
while [ $# != 0 ]
do
    case $1 in 
            -b) BKG=1
                shift
                ;;
            -d) ps -c  | fgrep "ScreenSaver"
                exit 0 
                ;;

            -f) SWITCHES=" -foreground " 
                shift
                ;;
            -l) echo "==== USER $USER  [ /Users/$USER/Library/Screen Savers] ======"
                ls  /Users/$USER/Library/Screen Savers/ | fgrep .saver
                echo "==== SYSTEM [/Library/Screen Savers/] ======"
                ls  /Library/Screen Savers/ | fgrep .saver
                exit 0
                ;;
            -k) killsavers
                exit 0 
                ;;
            -r) SWITCHES="$SWITCHES -module Random" 
                shift
                ;;
            -m) SWITCHES="$SWITCHES -module $2" 
                shift
                shift
                ;;  
                
            *)  usage  
                ;;
        esac
        
done

killsavers

case $BKG in
    1)  $NICE $SAVER $SWITCHES & ;;
    *)  exec $NICE $SAVER $SWITCHES  ;;
esac

参考

Yohan

I want to change the screensaver text to some string (say mystring = “”) from cmd, and can I put the code in a .bat file?REPLYLINK

  • Emielrem setup screensaver with text over screen
    reg add “HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\TeXt”, “my text”
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop\BackgroundColor”, “0 0 0”
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop\TextColor”, “0 128 0”
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop\Size”, “20”
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop\Speed”, “4”
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop\Attributes”, “10001”
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop\CharSet”, “0”rem Set screensaver application
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop” /v SCRNSAVE.EXE /t REG_SZ /d %windir%\system32\ssmarque.scr /f
    rem set screen saver start to 10 minutes
    reg add “HKEY_CURRENT_USER\Control Panel\Desktop” /v ScreenSaveTimeOut /t REG_SZ /d 600 /f

Setting up the Screensaver Share(https://deployhappiness.com/setting-the-default-logon-screensaver-with-group-policy/)

First, you will need a share that allows domain computers to read/execute. We use our Application Deployment share for our default logon screensaver files. Next, get your hands on ssmypics.scr. This is the “My Pictures” screensaver that can be found in C:\Windows\System32 on any Windows XP machine. If you can’t get your hands on an XP machine, here is a zip file containing the screensaver: ssmypics

Copy this screensaver to the network share. Then create a sub-folder named Pictures. If you will be delegating the announcement, give those users (or a group they belong to) the ability to modify this folder.

Logon ScreenSaver

Create the File Preferences

In the GPMC, create a new a GPO named Default Logon Screensaver. Edit it and navigate to Computer Configuration/Preferences/Windows Settings/Files/. Create a new file preference that copies ssmypics.scr from your network share to C:\Windows\System32\. Set the Preference Action to Create.

Logon ScreenSaver

Create a second file preference that copies the contents from the Pictures sub-folder to a local folder. In my GPO, the files are copied from the share to C:\ProgramData\ScreenSaver\. Set this Preference Action to Create as well.

it appears that I misspelled pictures…

Create the Registry Preferences

While still under Computer Configuration, select Registry and create the following six registry preferences. All will be created under HKEY_USERS. The list below is formated as: KEY PATH  –  VALUE NAME  –  VALUE TYPE  –  VALUE DATA

  • .DEFAULT\Control Panel\Desktop  ScreenSaveActive  REG_SZ  1
  • .DEFAULT\Control Panel\Desktop  ScreenSaveisSecure  REG_SZ  0
  • .DEFAULT\Control Panel\Desktop  ScreenSaveTimeOut  REG_SZ  90
  • .DEFAULT\Control Panel\Desktop  SCRNSAVE.EXE  REG_SZ  C:\Windows\System32\ssmypics.scr
  • S-1-5-19\Control Panel\Screen Saver.Slideshow  ImageDirectory  REG_SZ  C:\ProgramData\ScreenSaver
  • S-1-5-19\Control Panel\Screen Saver.Slideshow  ChangeInterval  REG_DWORD  15000
Logon ScreenSaver

Here are some of the values that you might want to adjust:

  • ScreenSaveTimeOut: The time (in seconds) until the screensaver becomes active. In the example above, it is 90 seconds.
  • ImageDirectory: The location of the locally copied screensaver pictures
  • ChangeInterval: The time between each picture change in the logon screensaver.

The only thing left to do is to link the GPO and test it out! You will need to populate the pictures sub-folder if you haven’t. After rebooting a machine (or running a GPUpdate), you should see your logon screensaver activate.

If you plan to use this as a distributed announcement system, you can easily generate the screensaver pictures in PowerPoint. Just save the Powerpoint as a .JPG into your pictures folder. Each slide in the PowerPoint will be saved as a picture.

Troubleshooting

If your logon screensaver doesn’t activate after the ScreenSaveTimeOut value has expired, adjust that time to a low value (such as 5 seconds). This will assist in troubleshooting.

Next, check the Application Log in Event Viewer for any Group Policy Preferences errors. If you see any Preference errors, check out this troubleshooting guide. Finally, ensure that the ssmypics.scr exists in System32 and that your local pictures actually exist. If you still have issues after this, just leave a comment below.

每日获取Bing图片并设为壁纸

function Save-BingTodayImage()
{
    #必应图片故事API
    $bingImageApi ='http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=zh-cn'
    $bingUri = 'http://www.bing.com/'
 
    # 获取图片链接
    [xml]$bingImageXml = (Invoke-WebRequest -Uri $bingImageApi).Content
    Write-Host " 今日图片故事: $( $bingImageXml.images.image.copyright ) "
    $imgLink = '{0}{1}' -f $bingUri , $bingImageXml.images.image.url
 
    # 下载和保存图片
    $imageDir = "$HOME\Pictures\Bing\"
    if( -not (Test-Path $imageDir) )
    {
        mkdir $imageDir | Out-Null
    }
    $imageFile = Join-Path $imageDir ( '{0}.jpg' -f $bingImageXml.images.image.fullstartdate)
 
    Invoke-WebRequest -Uri $imgLink -OutFile $imageFile
 
    return $imageFile
}
 
Function Set-DesktopWallPaper($imagePath)
{
 Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $imagePath
 RUNDLL32.EXE USER32.DLL UpdatePerUserSystemParameters ,1 ,True
}
 
# 获取今日必应背景图片
$image=Save-BingTodayImage
 
#设置为桌面墙纸
Set-DesktopWallPaper -imagePath $image

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注