# Need help with an export script

**URL:** <https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348>\
**Category:** Automation\
**Created:** [January 9, 2012, 11:49am UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348 "2012-01-09T11:49:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TylerGred](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@TylerGred](https://discourse.devontechnologies.com/u/TylerGred)\
**Post date:** [January 9, 2012, 11:49am UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/1 "2012-01-09T11:49:21Z")

</div>

I’m trying to create a script that will export the current database files (a mimic of File\>Export\>Files and Folders) to a specific folder.

```auto

tell application "DEVONthink Pro"
	try
		if not (exists current database) then error "No database is open."
		set this_database to current database
		set database_name to name of current database
		set this_date to do shell script "date +%Y-%m-%d"
		set export_name to this_date & " | " & database_name as string
	end try
end tell
tell application "Finder"
		make new folder at alias "Macintosh HD:Users:user:Desktop:" with properties {name:export_name}
end tell
tell application "DEVONthink Pro"
	export data of this_database to "Macintosh HD:Users:user:Desktop:"
end tell
end tell

```

A few things I’m having trouble with:  
Getting the right syntax for DevonThink Pro to export the files and folders of the current group…

I’d like to export the content to a new folder I created, but how would I reference that folder?

Sorry, but my AppleScript knowledge is bare, so I appreciate any help you can send my way.

Thank you.

---

<div class="post-metadata">

**Author:** ![korm](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/e0b2c6/32.png) [@korm](https://discourse.devontechnologies.com/u/korm)\
**Post date:** [January 9, 2012, 12:20pm UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/2 "2012-01-09T12:20:26Z")

</div>

Seems to me it would be simpler to use the DEVONthink actions in Automator and build a workflow to do this. Those actions include selecting databases, groups, exporting, etc.

---

<div class="post-metadata">

**Author:** ![TylerGred](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@TylerGred](https://discourse.devontechnologies.com/u/TylerGred)\
**Post date:** [January 9, 2012, 1:09pm UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/3 "2012-01-09T13:09:30Z")

</div>

I’m having a few issues with Automator.

For example my Receipts Database

I can create a folder with Today’s date in My Documents\>Receipts Exports  
I can export my database, but how to I select the folder that has not yet been created during the workflow?

---

<div class="post-metadata">

**Author:** ![ndouglas](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/ndouglas/32/7079_2.png) [@ndouglas](https://discourse.devontechnologies.com/u/ndouglas)\
**Post date:** [January 10, 2012, 6:50pm UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/4 "2012-01-10T18:50:13Z")

</div>

Hi!

This script might be what you’re looking for.

```auto

tell application "DEVONthink Pro"
	try
		if not (exists current database) then error "No database is open."
		set this_database to current database
		set this_root to root of current database
		set database_name to name of current database
		set this_date to do shell script "date +%Y-%m-%d"
		set export_name to this_date & " | " & database_name as string
	end try
end tell
try
	tell application "Finder"
		set this_folder_properties to the properties of (make new folder at alias "Macintosh HD:Users:ndouglas:Desktop:" with properties {name:export_name})
		set this_folder to folder (name of this_folder_properties) of (container of this_folder_properties) as string
		set this_path to POSIX path of this_folder
	end tell
	tell application "DEVONthink Pro"
		export record this_root to this_path
	end tell
end try

```

Does that help? Let me know if you have any problems, and thanks for your post 🙂

---

<div class="post-metadata">

**Author:** ![TylerGred](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@TylerGred](https://discourse.devontechnologies.com/u/TylerGred)\
**Post date:** [January 11, 2012, 8:04am UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/5 "2012-01-11T08:04:44Z")

</div>

YES!

Thank you so much for your help! This script is finally finished!

---

<div class="post-metadata">

**Author:** ![korm](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/e0b2c6/32.png) [@korm](https://discourse.devontechnologies.com/u/korm)\
**Post date:** [January 11, 2012, 5:18pm UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/6 "2012-01-11T17:18:36Z")

</div>

Note that the script posted above is hardcoded to the specific structure of Nathan’s machine. You’ll need to adjust the “set this\_folder\_properties …” statement to the desired destination on your machine, or tell Finder to open a file dialog and select a destination.

---

<div class="post-metadata">

**Author:** ![ndouglas](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/ndouglas/32/7079_2.png) [@ndouglas](https://discourse.devontechnologies.com/u/ndouglas)\
**Post date:** [January 11, 2012, 6:52pm UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/7 "2012-01-11T18:52:24Z")

</div>

> [@korm](#):
>
> Note that the script posted above is hardcoded to the specific structure of Nathan’s machine. You’ll need to adjust the “set this\_folder\_properties …” statement to the desired destination on your machine, or tell Finder to open a file dialog and select a destination.

Good catch, korm. The same is true for the script from which I adapted it.

---

<div class="post-metadata">

**Author:** ![jprint714](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@jprint714](https://discourse.devontechnologies.com/u/jprint714)\
**Post date:** [July 15, 2012, 11:37pm UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/8 "2012-07-15T23:37:22Z")

</div>

Hi,

I’m trying to rig up a version of this script. How do I adjust the “set this\_folder\_properties …” statement so that it saves to a folder on an external HD? Also, where would I save this script? To DTP’s Scripts folder? Somewhere else? Excuse my ignorance w/ AppleScripts…

---

<div class="post-metadata">

**Author:** ![system](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/4/4e6ff70c96be2eb307a274d890bba8d71ba671b3.png) [@system](https://discourse.devontechnologies.com/u/system)\
**Post date:** [January 21, 2022, 11:14am UTC](https://discourse.devontechnologies.com/t/need-help-with-an-export-script/13348/9 "2022-01-21T11:14:41Z")

</div>

Closed on January 21, 2022, 11:14am UTC


