I have been trying for a while to create an Applescript that would launch a create file dialog box. I would then enter the file name to create, the location to save to and the Tags to assign.
Everybody online told me a way to do it which involved basically having a script that says if a Finder is open save to the current folder if no window open then save to desktop. Then open a simple dialog box and create file.
I though wished to do it another way. i wanted to have a save file as type box appear whereby you enter the name of the file to create and the location and then assign Tag to it.
I managed to get the first part working but could not get the script to assign a Tag.
I managed to stumble upon the solution by accident so here is my full script program for anyone it may help
The code that assigns the Tag(s) is the last part. Write filename to filename
I wrote it thinking it would do something else. However what I think it actually does is take the contents of the variable named filename and writes them to the parameters of the actual file it creates.
The contents being the location to save the file. The location of the file just created is the same so nothing changes, then the name of the file, that too is the same so it is not changed. Lastly the Tag which is not present so is then set to the newly created file.
and hey presto! I think this is not the correct way to assign a tag to a file you create with Applescript but it works and does so with one line of code so I hope you find it useful
Everybody online told me a way to do it which involved basically having a script that says if a Finder is open save to the current folder if no window open then save to desktop. Then open a simple dialog box and create file.
I though wished to do it another way. i wanted to have a save file as type box appear whereby you enter the name of the file to create and the location and then assign Tag to it.
I managed to get the first part working but could not get the script to assign a Tag.
I managed to stumble upon the solution by accident so here is my full script program for anyone it may help
Code:
set filename to choose file name with prompt "choose file" default name "untitled.txt" default location (folder of the front window) as alias
open for access filename with write permission
write filename to filename
I wrote it thinking it would do something else. However what I think it actually does is take the contents of the variable named filename and writes them to the parameters of the actual file it creates.
The contents being the location to save the file. The location of the file just created is the same so nothing changes, then the name of the file, that too is the same so it is not changed. Lastly the Tag which is not present so is then set to the newly created file.
and hey presto! I think this is not the correct way to assign a tag to a file you create with Applescript but it works and does so with one line of code so I hope you find it useful
Last edited by a moderator: