{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner

Slide Show Screen Saver From The Command Line

// description of your code here

# create a custom slide show screen saver in "${HOME}/Library/Screen Savers" (on Mac OS X)
# usage: cslidesaver [name] [pics]

function cslidesaver() {

   declare EmptySlideSaverDir NewSlideSaverDir slidesaver_name
   declare -i disable_pathname_expansion=0

   if [[ $# -lt 2 ]]; then echo 'Minimum number of arguments: 2'; return 1; fi

   #set -e   # exit immediately if a command exits with a non-zero status


   EmptySlideSaverDir="${HOME}/Library/Screen Savers/Empty.slideSaver"
   NewSlideSaverDir="${HOME}/Library/Screen Savers/${slidesaver_name}.slideSaver"

   # make sure there is no trailing slash

   export EmptySlideSaverDir

   /bin/mkdir -p "${HOME}/Library/Screen Savers"

   if [[ -d "${NewSlideSaverDir}" ]]; then
      echo "Directory already exists: ${NewSlideSaverDir}"
      return 1

   # create a picture-free slide show screen saver directory structure based on Forest.slideSaver
   if [[ ! -d "${EmptySlideSaverDir}" ]]; then
      /usr/bin/sudo /bin/cp -R "/System/Library/Screen Savers/Forest.slideSaver" "${EmptySlideSaverDir}"

      ###/usr/bin/sudo /usr/sbin/chown -R "$(/usr/bin/logname)":"$(/usr/bin/logname)" "${EmptySlideSaverDir}"
      ###/usr/bin/sudo /usr/sbin/chown -R ${SUDO_UID}:${SUDO_GID} "${EmptySlideSaverDir}"       # cf. sudo env
      /usr/bin/sudo /bin/bash -c '/usr/sbin/chown -R ${SUDO_UID}:${SUDO_GID} "${EmptySlideSaverDir}"'    # requires: export EmptySlideSaverDir

      /usr/bin/find -x "${EmptySlideSaverDir}/Contents/Resources" -type f -delete
      /usr/bin/find -x "${EmptySlideSaverDir}" -type d -print0 | /usr/bin/xargs -0 /bin/chmod 0755
      /usr/bin/find -x "${EmptySlideSaverDir}" -type f -print0 | /usr/bin/xargs -0 /bin/chmod 0644

   # enable pathname expansion
   if [[ "${SHELLOPTS}" == *noglob* ]]; then set +f; disable_pathname_expansion=1; fi

   /bin/cp -Rp ${@} "${EmptySlideSaverDir}/Contents/Resources"

   /bin/cp -Rp "${EmptySlideSaverDir}" "${NewSlideSaverDir}"

   ###/usr/sbin/chown -R "$(/usr/bin/logname)":"$(/usr/bin/logname)" "${NewSlideSaverDir}"
   #/usr/sbin/chown -R "$(/usr/bin/logname)":"$(/usr/bin/id -gn)" "${NewSlideSaverDir}"
   /usr/sbin/chown -R $(/usr/bin/id -u -r):$(/usr/bin/id -g -r) "${NewSlideSaverDir}"

   /usr/bin/find -x "${NewSlideSaverDir}" -type d -print0 | /usr/bin/xargs -0 /bin/chmod 0755
   /usr/bin/find -x "${NewSlideSaverDir}" -type f -print0 | /usr/bin/xargs -0 /bin/chmod 0644

   /usr/bin/find -x "${EmptySlideSaverDir}/Contents/Resources" -type f -delete

   if [[ $disable_pathname_expansion -eq 1 ]]; then set -f; fi

   /usr/bin/open -a 'System Preferences' /System/Library/PreferencePanes/ScreenSaver.prefPane

   return 0


cslidesaver mysaver1 ~/Pictures/pic-{1,2,3}.jpg
cslidesaver mysaver2 ~/Pictures/pic-*.jpg
cslidesaver mysaver3 ~/Pictures/picfolder
cslidesaver mysaver4 /Users/Shared/pic1.jpg ~/Pictures/pic2.jpg

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks