這則指令我先前曾在 T 客邦分享過 v0.1 版本「文章連結:自訂 macOS 截圖設定終端機指令」
最近有朋友問我:「截圖時能不能連同滑鼠游標一起拍進去?」(macOS 預設會隱藏游標)。事實上,這可以透過一條強制開啟的指令來達成:defaults write com.apple.screencapture showsCursor -bool true; killall SystemUIServer考量到我之前寫的「ScreenshotConfig」腳本尚未支援此項目,決定順手將它升級至 v0.2 版本,並分享給大家。
如何使用?
當你需要修改截圖設定時,直接 Double Click(按兩下) 執行這支 ScreenshotConfig_v0.2.sh 即可。 執行後會出現對話視窗,請依序選擇你想要的設定項目:
選擇儲存截圖的位置
設定截圖後的檔案路徑(預設為桌面)。若有特定專案需求,可指定至專案資料夾,讓這段期間的截圖集中管理;待工作完成後再重設回桌面即可。

設定截圖格式
支援 png、jpg、pdf、heic。若需保留背景透明度,請務必選擇 png。

設定檔名前綴
自訂檔名開頭。例如設定為「Screenshot」,產出的檔名會像這樣:Screenshot 2026-02-10 14.25.19.png。

選擇是否關閉陰影
擷取單一視窗時,macOS 預設會帶有深色陰影。關閉陰影可讓畫面更清爽,減少排版干擾。

是否顯示滑鼠游標
本次新增的功能。選擇「顯示游標」對於製作教學圖示非常友善,能更直觀地指引重點。

複製指令碼
請將下列代碼複製並貼到文字編輯器,另存新檔為 ScreenshotConfig_v0.2.sh。
#!/bin/zsh
# ScreenshotConfig_v0.2.sh
# Copyright (c) 2025-2026 Alrin
check_cancel() {
if [[ $? -ne 0 ]] || [[ -z "$1" ]] || [[ "$1" == "false" ]]; then
echo "🚫 使用者已取消設定,程式結束。"
exit 0
fi
}
echo "🔧 開始設定截圖偏好..."
save_path=$(osascript <<EOT
try
set defaultPath to (path to desktop folder) as text
set posixDefaultPath to POSIX path of defaultPath
set thePath to choose folder with prompt "請選擇儲存截圖的位置:" default location POSIX file posixDefaultPath
POSIX path of thePath
on error
return "false"
end try
EOT
)
check_cancel "$save_path"
format=$(osascript <<EOT
try
set theChoice to choose from list {"png", "jpg", "pdf", "heic"} with prompt "請選擇圖片格式:" default items {"png"}
if theChoice is false then return "false"
return item 1 of theChoice
on error
return "false"
end try
EOT
)
check_cancel "$format"
prefix=$(osascript <<EOT
try
set theResponse to display dialog "請輸入檔名前綴:" default answer "Screenshot" buttons {"取消", "確定"} default button "確定"
return text returned of theResponse
on error
return "false"
end try
EOT
)
check_cancel "$prefix"
disable_shadow=$(osascript <<EOT
try
set theChoice to choose from list {"開啟陰影", "關閉陰影"} with prompt "視窗截圖時是否顯示陰影?" default items {"開啟陰影"}
if theChoice is false then return "false"
return item 1 of theChoice
on error
return "false"
end try
EOT
)
check_cancel "$disable_shadow"
show_cursor=$(osascript <<EOT
try
set theChoice to choose from list {"顯示游標", "隱藏游標"} with prompt "截圖時是否包含滑鼠游標?" default items {"顯示游標"}
if theChoice is false then return "false"
return item 1 of theChoice
on error
return "false"
end try
EOT
)
check_cancel "$show_cursor"
echo "📝 正在寫入設定..."
defaults write com.apple.screencapture location "$save_path"
defaults write com.apple.screencapture type "$format"
defaults write com.apple.screencapture name "$prefix"
if [[ "$disable_shadow" == *"關閉陰影"* ]]; then
defaults write com.apple.screencapture disable-shadow -bool true
else
defaults write com.apple.screencapture disable-shadow -bool false
fi
if [[ "$show_cursor" == *"顯示游標"* ]]; then
defaults write com.apple.screencapture showsCursor -bool true
else
defaults write com.apple.screencapture showsCursor -bool false
fi
killall SystemUIServer
killall screencaptureui 2>/dev/null
echo "✅ 所有截圖設定已更新!"
echo "📍 儲存位置:$save_path"
echo "📄 格式:$format"
echo "🖼️ 檔名前綴:$prefix"
echo "🖱️ 游標顯示:$show_cursor"
macOS 上執行 Shell Script 的一些必要設定
指定以「終端機」開啟
由於 .sh 檔案預設可能被識別為文字檔,有兩種執行方式:
- 手動執行:開啟終端機,將檔案拖入視窗(會自動帶入路徑),按下 Enter。
- 預設執行(推薦):
- 在 Finder 點選該檔案,按下
Command + I叫出「取得資訊」。 - 在「打開檔案的應用程式」下拉選單中,選擇 「工具程式 > 終端機.app」。
- 點擊下方的 「全部更改⋯」。以後只需雙擊腳本即可自動執行。
- 在 Finder 點選該檔案,按下
不過當你要執行 .sh 文件的時候,你可能還會遇到「隱私權與安全性、指令檔沒有執行權限」這兩個問題。
解決安全性與權限問題
在執行過程中,你可能會遇到以下狀況:
- 未識別的開發者: macOS 安全機制可能會阻擋執行。請前往「系統設定 > 隱私權與安全性」,找到該腳本並點擊「仍要開啟」。
- Permission denied(權限不足): 若出現此提示,表示檔案尚無執行權限。請在終端機輸入以下指令(後方請帶入檔案實際路徑):
chmod +x ScreenshotConfig_v0.2.sh
最後
這是我眾多自己寫的 Mac 小程式之一,目前努力的在學習 Swift,希望有招一日可以變成真正的開發者。
使用此程式時,請保留上方的版權註記。如果這支工具對你有幫助,歡迎留言互動或透過 vocus 贊助一杯咖啡,這對我是很大的鼓勵!

















