Simple subgroup creation

I was working out some details on a Support Ticket where I needed to generate a series of subGroups quickly. I took 5 minutes and put this together.

This is a simple script that shows a simple but effective use of repeat until…

tell application id "DNtp"
	set bt to ""
	set groupLoc to current group
	repeat until bt = "Done"
		set {bt, groupName} to {button returned, text returned} of (display dialog "Enter the name of the Group you want to create." default answer "" buttons {"OK", "Done"} default button "OK")
		if groupName ≠ "" then create record with {name:groupName, type:group} in groupLoc
	end repeat
end tell

If you don’t specifically have a group selected, it will create Groups at the database’s root.

PS: Yes, you can select a Group and press Command-Shift-N to make a new subGroup. This is a learning tool which can hopefully help someone.

Excellent little script, thanks. 8)

See also

Great minds, and all that … 8)

I hope it learns you somethin’. :mrgreen:

PS: Do note that Applescript does allow for a more natural English phrasing…
repeat until bt is “Done”
if groupName is not equal to… , if you prefer.

@korm: True, true.

It does! I have tried to get to grips with AppleScript but spmehow my brain refuses to get round it. I have looked at all sorts of online tutorials ut aways end up quite confused…I wish there was a simple guide that is easy to understand and would at least teach me enough to have a grounding which I could develop. Anyone know of one? is the best resource for all things Applescript.

That being said, the best way is just getting your hands dirty. Brute force is often required but it’s so worth it in the end. (And sometimes it can be lucrative, as I’ve done it professionally for years. :smiley: )

I have been to MacScripter but what I am looking for is a book I think that uses a step by step approach, may have a look at the “Dummies” one.

I suggest starting off with a simple project in the Finder. (While DEVONthink is very capable from an Applescript standpoint, it is not the best starting point for beginning scripters.)

Here’s a quick tip: In Applescript Editor, always have Window > Library open for quick access to Applescript dictionaries.

Thanks for this. I shall bare that tip in mind. … index.html

Good news! As of OS X 10.10, you will be able to write code in Javascript instead of Applescript, but still control apps the same way! … index.html

I found ‘Learn AppleScript The Comprehensive Guide to Scripting and Automation on Mac OS X’ by Hamish Sanderson & Hanaan Rosenthal and published by apress, to be excellent.

There is a lot of stuff you can skip if you are only interested in Devonthink but it shows you the basics quite well. Remember that every application’s object model is different and applying applescript to the particular application is really the hardest thing - its very idiomatic. Most importantly remember you need to learn only a very small subsection of applescript and DT’s object model to start to do useful stuff.

To learn DT applescript I recommend the following approach:
a) Work out the basics of applescript - syntax, loops variables etc. Just enough to be able to read the skeleton of a script. Reading a book from start to finish will just leave you confused.
b) Pick a simple task that you want to do in DT such as get a list of the descriptions of of selected document.
c) Dig into the forums, reading and searching, annotating interesting scripts, seeing how other people have tackled tasks, learning the idioms. It almost certain that somehow in the forum will have wanted to do something very similar to what you want to do. Finding a script on the forum that does something related to what you want to do, is a great start.
d) While you read the scripts in the forum, run them, change them and see what is happening.

Its a cascading effect. As soon as you get your first script running, you will be saying to yourself, well I wonder if I can change it to do …


Bluefrog wrote

I disagree with this. I think Devonthink is an excellent starting point to learn applescript. Devonthink’s object model is very good and confined and the examples of using it are better than almost any other applescripts you will find on the net. As an example, its much easier to use manipulate documents in DT than it is in finder.

Also if you have worked with DT for a while you will almost certainly have thought ‘I would like to do …’. Knowing what you want to do is often the hardest first step.