hi, first post to this forum, after switching from BBEdit to TextMate. while I'm discovering everyday the benefit of this change, I came across a syntax problem with a Applescript I was using successfully with BBEdit.
the principle of the script was to create folders and sub-folders, then create a new document in one of them with my text editor, save it with a title, bringing it to the front for entry. changing the app to TextMate, I get an error: [quote] AppleEvent Handler failed: expect end of line but get "to" [/ quote]
I have posted an entry on MacScripter, to hear that TextMate was "poorly scriptable, even Standard Suite is badly implemented". any solution to contradict that?! below the script in question:
set theFolder to choose folder with prompt "Create/Choose Client Project folder" try set briefFolder to ((theFolder as text) & "Brief") as alias on error tell application "Finder" to set briefFolder to make new folder at theFolder with properties {name:"Brief"} end try tell application "Finder" set capturesFolder to make new folder at theFolder with properties {name:"Captures"} end tell tell application "TextMate" -- was BBEdit set briefDoc to make new document at beginning with properties {name:"$.tasks"} -- was "$.todo" save briefDoc to ((briefFolder as text) & "$.tasks") end tell tell application "TextMate" to activate -- was BBEdit
-- cheers, Pascal
On Mon, Mar 17, 2008 at 8:32 PM, pascal@g ymostudio@gmail.com wrote:
the principle of the script was to create folders and sub-folders, then create a new document in one of them with my text editor, save it with a title, bringing it to the front for entry.
If you delete everything after the 'tell application "Finder"' clause and insert
set briefDoc to (POSIX path of briefFolder) & "$.tasks" do shell script ("touch " & briefDoc & "; mate " & briefDoc)
it should do what you want. I have to say that the use of a dollar sign as a file name scares me a bit because it's a special character in the shell, but with this change the script worked for me.
(I am curious why the creation of the Captures folder isn't put into a 'try/on error' block like the creation of the Briefs folder, but I'm sure you have your reasons.)
I have posted an entry on MacScripter, to hear that TextMate was "poorly scriptable, even Standard Suite is badly implemented". any solution to contradict that?!
TextMate is certainly not as AppleScriptable as BBEdit, but it is far more scriptable with Perl, Python, Ruby, and the shell. In my book, this is a big win for TextMate and the reason I switched a couple of years ago.
Thank you for your quick answer. You made few interesting points! - the "$" acts as a warning for me to re-assign a specific (client) name to the document. not a brilliant idea, which I will change - the "try/on" spilt is more to do with my lack of knowledge on Applescript: I have just adapted one found on a forum.
I am having difficulties implementing your suggestions, not having enough knowledge of the Applescript syntax; I mainly do html and css coding, and have adapted a script to my needs.
Would you mind to clarify or correct directly the full script below? It would be much appreciated...
set theFolder to choose folder with prompt "Create/Choose Client Project folder" try set briefFolder to ((theFolder as text) & "Brief") as alias on error tell application "Finder" set briefFolder to (POSIX path of briefFolder) & "x.tasks" do shell script ("touch " & briefDoc & " ;mate " & briefDoc) end try tell application "Finder" set capturesFolder to make new folder at theFolder with properties {name:"Captures"} set processedFolder to make new folder at theFolder with properties {name:"Processed"} set HiResFolder to make new folder at processedFolder with properties {name:"High-Res Images"} set LoResFolder to make new folder at processedFolder with properties {name:"Low-Res Images"} set trashFolder to make new folder at theFolder with properties {name:"Trash"} end tell
PS: what are the details of your book? -- cheers, Pascal
On 18/03/2008, at 11:26 AM, Dr. Drang wrote:
On Mon, Mar 17, 2008 at 8:32 PM, pascal@g ymostudio@gmail.com wrote:
the principle of the script was to create folders and sub-folders, then create a new document in one of them with my text editor, save it with a title, bringing it to the front for entry.
If you delete everything after the 'tell application "Finder"' clause and insert
set briefDoc to (POSIX path of briefFolder) & "$.tasks" do shell script ("touch " & briefDoc & "; mate " & briefDoc)
it should do what you want. I have to say that the use of a dollar sign as a file name scares me a bit because it's a special character in the shell, but with this change the script worked for me.
(I am curious why the creation of the Captures folder isn't put into a 'try/on error' block like the creation of the Briefs folder, but I'm sure you have your reasons.)
I have posted an entry on MacScripter, to hear that TextMate was "poorly scriptable, even Standard Suite is badly implemented". any solution to contradict that?!
TextMate is certainly not as AppleScriptable as BBEdit, but it is far more scriptable with Perl, Python, Ruby, and the shell. In my book, this is a big win for TextMate and the reason I switched a couple of years ago.
-- Dr. Drang
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On Mon, Mar 17, 2008 at 11:22 PM, pascal@g ymostudio@gmail.com wrote:
I am having difficulties implementing your suggestions, not having enough knowledge of the Applescript syntax; I mainly do html and css coding, and have adapted a script to my needs.
You've put my two lines after the wrong 'tell application "Finder"'. I should have been more explicit in my message--electrons are cheap. Here is a script that does what your script wants to do:
-- get the base folder set theFolder to choose folder with prompt "Create/Choose Client Project folder"
-- get the Briefs subfolder, making it if it doesn't already exist try set briefFolder to ((theFolder as text) & "Brief") as alias on error tell application "Finder" to set briefFolder to (make new folder at theFolder with properties {name:"Brief"}) as alias end try
-- ensure that a set of subfolders exists try get ((theFolder as text) & "Captures") as alias on error tell application "Finder" to make new folder at theFolder with properties {name:"Captures"} end try try set processedFolder to ((theFolder as text) & "Processed") as alias on error tell application "Finder" to set processedFolder to (make new folder at theFolder with properties {name:"Processed"}) as alias end try try get ((processedFolder as text) & "Hi-Res Images") as alias on error tell application "Finder" to make new folder at processedFolder with properties {name:"Hi-Res Images"} end try try get ((processedFolder as text) & "Low-Res Images") as alias on error tell application "Finder" to make new folder at processedFolder with properties {name:"Low-Res Images"} end try try get ((theFolder as text) & "Trash") as alias on error tell application "Finder" to make new folder at theFolder with properties {name:"Trash"} end try
-- make a new file in the Briefs subfolder and open it in TextMate set briefDoc to (POSIX path of briefFolder) & "$.tasks" do shell script ("touch " & briefDoc & "; open -a TextMate " & briefDoc)
This may be unnecessarily verbose, but the 'try/on error' clauses will allow it to work regardless of whether the subfolders already exist. Your script assumes that "Captures," "Processed," etc. do not exist and will fail if they do.
I've also changed the shell script in the last line. Most people on this list will have the "mate" shell command available, but a newcomer may not.
Hope this works for you.
sorry to follow up only now, but I've been away.
the script works perfectly: THANK YOU. thanks also for taking the time to comment each section: I am always eager to learn, and this helps.
finally, can I ask you what is this "mate" shell command you refer to? what are the benefits? and how to set it up? -- cheers, Pascal
On 18/03/2008, at 11:34 PM, Dr. Drang wrote:
On Mon, Mar 17, 2008 at 11:22 PM, pascal@g ymostudio@gmail.com wrote:
I am having difficulties implementing your suggestions, not having enough knowledge of the Applescript syntax; I mainly do html and css coding, and have adapted a script to my needs.
You've put my two lines after the wrong 'tell application "Finder"'. I should have been more explicit in my message--electrons are cheap. Here is a script that does what your script wants to do:
-- get the base folder set theFolder to choose folder with prompt "Create/Choose Client Project folder"
-- get the Briefs subfolder, making it if it doesn't already exist try set briefFolder to ((theFolder as text) & "Brief") as alias on error tell application "Finder" to set briefFolder to (make new folder at theFolder with properties {name:"Brief"}) as alias end try
-- ensure that a set of subfolders exists try get ((theFolder as text) & "Captures") as alias on error tell application "Finder" to make new folder at theFolder with properties {name:"Captures"} end try try set processedFolder to ((theFolder as text) & "Processed") as alias on error tell application "Finder" to set processedFolder to (make new folder at theFolder with properties {name:"Processed"}) as alias end try try get ((processedFolder as text) & "Hi-Res Images") as alias on error tell application "Finder" to make new folder at processedFolder with properties {name:"Hi-Res Images"} end try try get ((processedFolder as text) & "Low-Res Images") as alias on error tell application "Finder" to make new folder at processedFolder with properties {name:"Low-Res Images"} end try try get ((theFolder as text) & "Trash") as alias on error tell application "Finder" to make new folder at theFolder with properties {name:"Trash"} end try
-- make a new file in the Briefs subfolder and open it in TextMate set briefDoc to (POSIX path of briefFolder) & "$.tasks" do shell script ("touch " & briefDoc & "; open -a TextMate " & briefDoc)
This may be unnecessarily verbose, but the 'try/on error' clauses will allow it to work regardless of whether the subfolders already exist. Your script assumes that "Captures," "Processed," etc. do not exist and will fail if they do.
I've also changed the shell script in the last line. Most people on this list will have the "mate" shell command available, but a newcomer may not.
Hope this works for you.
-- Dr. Drang
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On Mar 20, 2008, at 4:50 AM, pascal@g wrote:
finally, can I ask you what is this "mate" shell command you refer to? what are the benefits? and how to set it up?
The 'mate' command is a way to open files in TextMate from the command line (Terminal). Its main benefit is that it's faster to type
mate filename
than
open -a TextMate filename
but it has some other useful options, which you can learn about by typing 'mate -h' at the command line. You can learn how to install and use it in the TextMate manual:
http://macromates.com/textmate/manual/using_textmate_from_terminal
-- Dr. Drang