【AppleScript】連番フォルダを作る
AppleScriptで連番フォルダを作ります。
(*
連番フォルダを作ります
20180120 初回作成
*)
---設定項目
---フォルダ名 と 連番をツナグ文字
set theFileNameSep to "_"
tell application "Finder"
display alert "主名称+連番形式でフォルダを作成します\n\n最初のダイアログで『主名称』\n次のダイアログで『何個』作るか指定してください\n最後のダイアログで作成場所を指定します" as informational
end tell
tell application "Finder"
---主名称指定
display dialog "主名称を入力してください" default answer "NewFolderName" with icon 1 default button 2
if button returned of the result is "OK" then
set theFolderNameText to text returned of the result as text
else
return "終了"
end if
---何個作るか指定
display dialog "何個作りますか?(半角数字にしてね)" default answer "10" with icon 1 default button 2
if button returned of the result is "OK" then
set numMakeNumber to text returned of the result as number
else
return "終了"
end if
---作成先指定
set aliasMakeDir to (choose folder with prompt "フォルダを作る場所を指定してください" default location (path to desktop folder from user domain)) as alias
end tell
---フォルダ名初期化
set numFileNumber to 1 as number
---数量の桁数を判定
set theCntNo to the length of characters of (numMakeNumber as text) as number
---フォルダ作成のリピート
repeat numMakeNumber times
---数字のゼロサプレス
if theCntNo = 2 then
if numFileNumber < 10 then
set theFcount to "0" & numFileNumber as text
else
set theFcount to numFileNumber as text
end if
else if theCntNo = 3 then
if numFileNumber < 10 then
set theFcount to "00" & numFileNumber as text
else if numFileNumber < 100 then
set theFcount to "0" & numFileNumber as text
else
set theFcount to numMakeNumber as text
end if
else if theCntNo = 4 then
if numFileNumber < 10 then
set theFcount to "000" & numFileNumber as text
else if numFileNumber < 100 then
set theFcount to "00" & numFileNumber as text
else if numFileNumber < 1000 then
set theFcount to "0" & numFileNumber as text
else
set theFcount to numFileNumber as text
end if
else
set theFcount to numFileNumber as text
end if
---フォルダ名整形(名称 ツナギ文字 連番)
set theMakeFolderName to (theFolderNameText & theFileNameSep & theFcount) as text
---フォルダ名整形(連番 ツナギ文字 名称)
---set theMakeFolderName to (theFcount & theFileNameSep & theFolderNameText) as text
---フォルダ作成
tell application "Finder"
make new folder at aliasMakeDir with properties {name:theMakeFolderName}
end tell
---カウントアップ
set numFileNumber to numFileNumber + 1 as number
end repeat
| 固定リンク
「AppleScript」カテゴリの記事
- 濁音 半濁音 置換用レコード(2023.08.21)
- [AppleScript]キーノートの書類サイズを指定して作成(2022.01.09)
- [awk]行頭のスペースを削除する(subで置き換え)(2021.11.16)
- [SpotLight]選択範囲でSpotLight検索(2021.11.03)
- [AppleScript]リソースフォーク(カスタムアイコン)削除(2021.10.12)