-
-
Save lucianghinda/26e33c78a3f053d314cf to your computer and use it in GitHub Desktop.
Change the filetype to markdown .md and automatically open it with iA Writer without renaming.
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
on run {input, parameters} | |
set file_name to "untitled" | |
set file_ext to ".md" | |
set is_desktop to false | |
-- get folder path and if we're in desktop (no folder opened) | |
try | |
tell application "Finder" | |
set this_folder to (folder of the front Finder window) as alias | |
end tell | |
on error | |
-- no open folder windows | |
set this_folder to path to desktop folder as alias | |
set is_desktop to true | |
end try | |
-- get the new file name (do not override an already existing file) | |
tell application "System Events" | |
set file_list to get the name of every disk item of this_folder | |
end tell | |
set new_file to file_name & file_ext | |
set x to 1 | |
repeat | |
if new_file is in file_list then | |
set new_file to file_name & " " & x & file_ext | |
set x to x + 1 | |
else | |
exit repeat | |
end if | |
end repeat | |
-- create and select the new file | |
tell application "Finder" | |
activate | |
set the_file to make new file at folder this_folder with properties {name:new_file} | |
if is_desktop is false then | |
reveal the_file | |
else | |
select window of desktop | |
set selection to the_file | |
delay 0.1 | |
end if | |
end tell | |
tell application "iA Writer" | |
open the_file | |
end tell | |
return input | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment