Created
December 6, 2021 14:37
-
-
Save mint149/3cba3bb4d49e492dbfb64e5546102a3f to your computer and use it in GitHub Desktop.
溜まったデイリーノートをフォルダに整理するスクリプト。(iOSのScriptableアプリを使用)
This file contains 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
const iCloud = FileManager.iCloud(); | |
const vaultPath = iCloud.bookmarkedPath('hatopedia'); | |
const dailyNoteDirectory = `${vaultPath}/Daily Notes/`; | |
const numbersToKeep = 3; | |
const files = iCloud.listContents(dailyNoteDirectory); | |
const dailyNotes = files.filter(function(value) { | |
return value.startsWith('20') && value.endsWith('.md'); | |
}); | |
if(dailyNotes.length == 0){ | |
console.log('No daily notes.'); | |
return; | |
} | |
if(dailyNotes.length <= numbersToKeep){ | |
console.log(`Less than ${numbersToKeep} daily notes.`); | |
return; | |
} | |
dailyNotes.sort(); | |
dailyNotes.pop(); | |
dailyNotes.pop(); | |
dailyNotes.pop(); | |
console.log(`Target:${dailyNotes}`); | |
dailyNotes.forEach(element => { | |
let yearDirectoryPath = `${dailyNoteDirectory}/${element.slice(0,4)}`; | |
let distDirectoryPath = `${yearDirectoryPath}/${element.slice(0,7)}`; | |
let distPath = `${distDirectoryPath}/${element}`; | |
if(!iCloud.fileExists(yearDirectoryPath)){ | |
iCloud.createDirectory(yearDirectoryPath); | |
console.log(`Year directory created:${yearDirectoryPath}`); | |
} | |
if(!iCloud.fileExists(distDirectoryPath)){ | |
iCloud.createDirectory(distDirectoryPath); | |
console.log(`Month directory created:${distDirectoryPath}`); | |
} | |
iCloud.move(`${dailyNoteDirectory}/${element}`, `${distPath}`); | |
console.log(`Moved to:${distPath}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment