---
type: collection
section: snippets
generated_at: '2026-11-18T09:53:11+01:00'
total_entries: 2
tag_filter: UUID
---

# Snippets

## Rename Files to Random UUIDs via macOS Shortcuts

---
type: snippet
id: 2lpiw0jmwjyaammm
title: 'Rename Files to Random UUIDs via macOS Shortcuts'
url: 'https://www.jakubpelak.com/snippets/rename-files-to-random-uuids-with-shortcuts'
section: snippets
tags:
  - macOS
  - Shortcuts
  - AppleScript
  - Automation
  - UUID
published_at: 2026-04-22
---

A companion to the [Bash UUID rename snippet](https://www.jakubpelak.com/snippets/rename-png-files-to-random-uuids), this AppleScript is meant to be dropped into a "Run AppleScript" action inside the macOS Shortcuts app (or Automator as a Quick Action). It accepts the files passed in as input, generates a random lowercase UUID for each one, and renames the file in place while preserving the original extension — handy as a right-click service in Finder.

```applescript
on run {input, parameters}
  repeat with f in input
    set posixPath to POSIX path of f
    set ext to do shell script "basename " & quoted form of posixPath & " | sed 's/.*\\.//'"
    set uuid to do shell script "uuidgen | tr '[:upper:]' '[:lower:]'"
    set newName to uuid & "." & ext
    tell application "Finder"
      set name of (POSIX file posixPath as alias) to newName
    end tell
  end repeat
  return input
end run
```

> [!TIP]
> Set the shortcut’s input to "Files" and, if you want it in Finder’s context menu, enable "Use as Quick Action" → "Services menu" in the shortcut’s details.

## Rename PNG Files to Random UUIDs

---
type: snippet
id: kowznhljjrgeq9r2
title: 'Rename PNG Files to Random UUIDs'
url: 'https://www.jakubpelak.com/snippets/rename-png-files-to-random-uuids'
section: snippets
tags:
  - Automation
  - CLI
  - UUID
  - Script
published_at: 2025-03-09
---

A simple Bash script that renames all `.png` files in the current directory using randomly generated lowercase UUIDs. It ensures `uuidgen` is installed before execution and skips renaming if no PNG files are found.

```bash
#!/bin/bash

# Check if 'uuidgen' command is available
if ! command -v uuidgen &> /dev/null; then
  echo "uuidgen command not found. Please install it first."
  exit 1
fi

# Loop through all .png files in the current directory
for file in *.png; do
  # Skip if no PNG files found
  if [ ! -e "$file" ]; then
    echo "No PNG files found in the current directory."
    exit 0
  fi

  # Generate a random UUID v4 and convert to lowercase
  uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')

  # Rename the file
  mv "$file" "${uuid}.png"
done

echo "All PNG files have been renamed to random lowercase UUIDs."
```

> [!NOTE]
> Prefer a right-click service on macOS? See the AppleScript variant: [Rename Files to Random UUIDs via macOS Shortcuts](https://www.jakubpelak.com/snippets/rename-files-to-random-uuids-with-shortcuts).

