Last active
January 14, 2024 00:10
-
-
Save logic2design/80a2ad3da9ee7f72e3b68627bcf5a8b9 to your computer and use it in GitHub Desktop.
This routine will create a Project folder in a number of different apps.
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
############################################## | |
# Title: 2nd Brain Project Folders - KM Version | |
############################################## | |
# Iain Dunn | |
# Logic2Design | |
# www.logic2design.com | |
# [email protected] | |
# Last update: 17 July 2022 | |
# Version: 1 | |
# Contributors and sources | |
# | |
############################################## | |
# Configuration | |
############################################## | |
use framework "Foundation" | |
use framework "AppKit" | |
use scripting additions | |
set iconFolder to (((path to "docs") as string) & "Automation:" & "Icons:") -- Location of your Icons | |
set folderTemplates to (path to "docs" as text) & "Automation:Folders" -- Location of your folder templates | |
set oPath to "Users:ijd65:Library:Mobile Documents:iCloud~md~obsidian:Documents:logic2Design:1 Projects:" | |
property devonthinkPath : "/Users/ijd65/Databases/PARA.dtBase2" | |
set dt to short date string of (current date) | |
set tm to time string of (current date) | |
set revisedTime to tm as string | |
set myAMPM to text -1 thru -3 of revisedTime | |
set revisedTime to text 1 thru -7 of revisedTime | |
set revisedTime to revisedTime & myAMPM | |
set FullDate to dt & space & revisedTime | |
############################################## | |
# Code | |
############################################## | |
-- Select Project options | |
tell application "Keyboard Maestro Engine" | |
do script "E72807EE-CF06-441A-8167-9B8A34BE2770" --KM UID | |
-- or: do script "2nd Brain Project Folder" | |
-- or: do script "4D938092-EB23-420D-990F-A9B6383232BA" with parameter "Whatever" | |
set xfinder to getvariable "Finder" | |
set xthings3 to getvariable "Things 3" | |
set xmail to getvariable "Mail" | |
set xnotes to getvariable "Notes" | |
set xdevonthink to getvariable "DEVONthink" | |
set xobsidian to getvariable "Obsidian" | |
end tell | |
-- Project Name | |
set theProject to text returned of (display dialog "Enter the name of Project" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue") | |
--Finder | |
if xfinder = "1" then | |
set path_to_Project to (((path to "docs") as string) & "1 Projects:" & theProject & ":") | |
-- set thepath to ("file://localhost" & (POSIX path of path_to_Project)) as text | |
--set path_to_Project to (((path to "docs") as string) & "1 Projects:" & theProject & ":") | |
do shell script "mkdir -p " & (POSIX path of path_to_Project)'s quoted form | |
--Project Icon | |
set icon to choose file with prompt "Please choose an icon" default location POSIX path of iconFolder of type {"Public.image"} | |
set destPath to POSIX path of path_to_Project | |
set sourcePath to POSIX path of icon | |
set imageData to (current application's NSImage's alloc()'s initWithContentsOfFile:sourcePath) | |
(current application's NSWorkspace's sharedWorkspace()'s setIcon:imageData forFile:destPath options:2) | |
--Set link | |
--set thepath to ("file://localhost" & (POSIX path of path_to_Project)) as text | |
--set thepath to quoted form of ("file://localhost" & (POSIX path of path_to_Project)) as text | |
-- add Folder templates | |
display alert "Do you want to add Folder templates" buttons {"No", "Yes"} | |
if button returned of result = "Yes" then | |
--Folder templates | |
set folderToDuplicate to choose folder with prompt "Choose Folder(s) to Duplicate" default location POSIX path of folderTemplates with multiple selections allowed | |
tell application "Finder" | |
set theDestinationFolder to folder (path_to_Project) | |
set newFolder to duplicate folderToDuplicate to theDestinationFolder | |
end tell | |
end if | |
set theSeparator to " — " | |
set niceURL to {} | |
tell application "Finder" | |
set theDestinationFolder to folder (path_to_Project) | |
# Create aliases from the Finder selection in the alias hub | |
set theSelection to the theDestinationFolder as alias | |
set {theName, theURL} to {displayed name of theSelection, URL of theSelection} | |
set the end of niceURL to theName & theSeparator & theURL & return & return | |
end tell | |
# Put it to the clipboard as text | |
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {linefeed}} | |
set the clipboard to niceURL as text | |
set AppleScript's text item delimiters to saveTID | |
end if | |
if xmail = "1" then | |
tell application "Mail" | |
tell account "Fastmail" | |
set FolderName to "@Projects/" & theProject | |
make new mailbox with properties {name:FolderName} | |
end tell | |
activate | |
end tell | |
end if | |
--Things3 | |
if xthings3 = "1" then | |
tell application "Things3" | |
if not (exists area "Projects") then | |
set newArea to make new area ¬ | |
with properties {name:"Projects"} | |
end if | |
if xfinder = "1" then | |
set newProject to make new project ¬ | |
with properties {name:theProject, notes:niceURL} | |
set area of newProject to area "Projects" | |
else | |
set newProject to make new project ¬ | |
with properties {name:theProject} | |
set area of newProject to area "Projects" | |
end if | |
activate | |
end tell | |
end if | |
--Note | |
if xnotes = "1" then | |
set noteBody to "<body><h1 style color:blue;>" & theProject & ¬ | |
"</h1><br><h3 style=color:blue;>" & theURL & "</h3><br><p style=color:black; >" & FullDate & " - Project created" & "</p></body>" | |
set the FolderName to "Projects" | |
tell application "Notes" | |
tell account "iCloud" | |
if not (exists folder FolderName) then | |
make new folder with properties {name:FolderName} | |
end if | |
make new note at folder FolderName with properties {name:" ", body:noteBody} | |
tell folder FolderName | |
show (note 1 whose name is theProject) | |
end tell | |
end tell | |
end tell | |
end if | |
if xobsidian = "1" then | |
set path_to_Project to (((oPath) as string) & theProject & ":") | |
do shell script "mkdir -p " & (POSIX path of path_to_Project)'s quoted form | |
--set destination to alias path | |
--set theDate to (current date) as text | |
--set myText to theDate | |
--set textName to theProject & ".md" | |
--tell application "Finder" to make new file at destination with properties {name:textName, contents:myText} | |
end if | |
if xdevonthink = "1" then | |
tell application id "DNtp" | |
# Create DEVONthink Group if it doesn't exist | |
set projectLocation to "/1 Projects/" & theProject | |
set destination_database to open database devonthinkPath | |
set projectGroup to create location projectLocation in destination_database | |
end tell | |
end if | |
-- Reset variables | |
set xfinder to "0" | |
set xdevonthink to "0" | |
set xthings3 to "0" | |
set xmail to "0" | |
set xnotes to "0" | |
############################################## | |
# Functions | |
############################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment