Last active
October 22, 2025 05:10
-
-
Save AJABON/6b72277f2accf6b4313f356895e12b2f to your computer and use it in GitHub Desktop.
macOSのJXA: Finder項目をドロップすると同じ名前のフォルダを作成した中に移動するやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function openDocuments(docs) { | |
| var app = Application.currentApplication(); | |
| app.includeStandardAdditions = true; | |
| for (var i = 0; i < docs.length; i++) { | |
| var filePath = docs[i].toString(); | |
| // ファイル名と拡張子を除去 | |
| var fileName = filePath.split("/").pop(); | |
| var baseName = fileName.replace(/\.[^\.]+$/, ""); | |
| var dirPath = filePath.replace(/\/[^\/]+$/, ""); | |
| var newFolderPath = dirPath + "/" + baseName; | |
| // mkdir(存在しなければ作る) | |
| try { | |
| app.doShellScript('mkdir -p "' + newFolderPath + '"'); | |
| } catch (e) {} | |
| // mv(同名があっても上書き) | |
| try { | |
| app.doShellScript('mv -f "' + filePath + '" "' + newFolderPath + '/"'); | |
| } catch (e) {} | |
| // (任意)ログ出力 | |
| console.log("Moved: " + filePath + " → " + newFolderPath); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JXAのコードです。
スクリプトエディタ.appで新規ドキュメントを開き、ペーストして、
種類が「AppleScript」になっていたら「JavaScript」を選択して、
アプリケーションとして保存してください。