Applescript: Screenshot with hide desktop items?

@appleianer

Here is an improved version of your first script (the approach with the hidden flag):

set ssDir to POSIX path of (path to desktop as text)
set ssDate to current date
# For a shorter date string:
# set ssDate to short date string of ssDate & space & time string of ssDate
set ssName to "Screen Shot" & space & ssDate & ".png"

do shell script "chflags -h hidden ~/Desktop/*"
delay 2

do shell script "screencapture" & space & quoted form of (ssDir & ssName)

do shell script "chflags -h nohidden ~/Desktop/*"

Changes:

  • The script now simply hides all files before the screen shot and makes them visible again after the screen shot.
  • The original script had a toggle: if one of your files was already hidden it would make all files visible. IMO, this makes no sense for your purposes.
  • A cleaner variable structure.
  • For a shorter date format uncomment line #4
  • The -h switch in the chflags shell command is necessary in case you have symlinks on the Desktop.

However, I’m undecided if this approach (setting the hidden flags) or @ComplexPoint’s approach (changing the Finder setting) is the better one.

@ComplexPoint’s approach has some advantages:

  • It is using the Finder setting, which is made exactly for that.
  • It also hides Volume icons on the Desktop.

The drawback is that after changing the Finder setting the Finder has to be relaunched, which can take a bit of time if you have lots of windows open. (Two Finder relaunches per screen shot.)

2 Likes