Dummy has basic question: how to set folder path in AppleScript

Hello and sorry for a basic question.

I have an AppleScript which crashes because I did not define the folder path


The problematic line of AppleScript is

set _folderPath to my makeTempFolder()

Let’s say that I want to set folder path to my downloads folder:

If it is not asking too much, I would be grateful if you could clarify the syntax of set _folderPath to my makeTempFolder()

1- what is the purpose of “my” ?
2- why use parenthesis at the end of makeTempFolder() ?

thanks in advance for your time and help

“my” means that it’s a handler/function defined in the AppleScript, not a one defined in some scripting extension etc

() indicates that makeTempFolder() is call to a function/handler and not a variable. You should be able to find makeTempFolder defined in the AppleScript

1 Like

thank you very much.
this is the apple script. I have no clue how to enter the path. I tried all kinds of combinations.
I cannot find where makeTempFolder is defined in the AppleScript, now do I know how to define it.

on export()
    tell application id "com.evernote.Evernote"
        set _folderPath to my makeTempFolder()
        set _notebooks to notebooks
        repeat with _notebook in _notebooks
            set _notes to notes of _notebook
            if (count of _notes) > 0 then
                -- assumes notebook's name is a valid filename and not the same as another notebook's
                set _path to _folderPath & "/" & name of _notebook & ".enex"
                with timeout of 2 * 60 * 60 seconds
                    export _notes to POSIX file _path format ENEX with tags
                end timeout
            end if
        end repeat
    end tell
    do shell script "open " & _folderPath's quoted form
end export

on makeTempFolder()
    -- errAEPrivilegeError if inside of "tell"
    do shell script "mktemp -d -t 'EFEvernoteExport'"
end makeTempFolder

my export()

You don’t have to do anything, the function creates a temporary folder and use it. I haven’t tried the script but it should work as is.

1 Like

Just to build on the explanations by @jemostrom with an example, you can see the path being created and set to the variable if you do a simple test like this to see the content of the _folderPath variable:


Each time you run it, you should get a new path. You can read about the mktemp shell command being run here:

If you really wanted to use a common path of your own as above, you could skip the creation of a temporary folder and set it directly to the variable.

set _folderPath to "/Users/cyrus/Downloads"

Hope that helps.


@jemostrom @sylumer

thank you both for your comments

The script runs perfectly. Evernote exports each note in sequence as displayed in the activity window.

However, the script crashes at the very end, probably (my guess) when the folder is being created.

thank you for your detailed comment
as soon as I run the script, I get an error
that being said, the display path idea is excellent

You have missed a space after “dialog”, and it isn’t creating a folder like the ten folder creation shell command, it’s setting a variable to the output folder path. That would need to exist.

Also note most of your code is in export but in the example above you have moved some outside it, so you’ll be getting two temp folders with what you have and you are displaying the one Evernote is not using.

1 Like

I’m sorry, I don’t understand. If you want to stop there I totally understand. I have taken enough of your time and patience

You look to be combining previous points in an unusual way and with incorrect syntax, so let’s take a step back and see if we can get you back on track.

What are you ultimately trying to do here?

  1. Run the original script that utilise a temporary folder.
  2. Run a modified script with the folder set to /Users/cyrus/Downloads.
  3. Run a modified script with the folder set to some other path that already exists.
  4. Something else; that you can describe?
1 Like

A very good point.

I want to convert my evernote notes to EagleFiler.

There is a script to do so both recommended by the developer and on the developer’s site.

Here is the script.

If I follow your approach, you are right, I am making contorted amateur attempts at solving a problem without having described the problem.

. the script seems to run flawlessly sorting through and exporting evernote notebooks and notes (I see it on the evernote activity window)
, at the end the script crashes with the error message below. I think that the crash is at the stage of the temp folder creation because it happens at the end, the error message mentions file or directory and I am unable to find a EFEvernoteExport folder in my Mac after the script runs.

So you are right, my questions represent my amateur attempts at troubleshooting the problem. I should have described the problem in the first place

thanks again very much

Right, let’s take a simplified approach with a script based on the script you shared originally.

set EXISTING_OUTPUT_DIR to "~/Desktop/EN_out/"
set MAX_SIZE to 20

tell application "Evernote Legacy"
	set _notebooks to notebooks
	repeat with _notebook in _notebooks
		set _notes to notes of _notebook
		if ((count of _notes) ≤ MAX_SIZE) and ((count of _notes) > 0) then
			set _path to EXISTING_OUTPUT_DIR & name of _notebook & ".enex"
			with timeout of 2 * 60 * 60 seconds
				export _notes to POSIX file _path format ENEX with tags
			end timeout
		end if
	end repeat
end tell

Important Points

  1. I’ve replaced the whole temporary directory business with just a directory on the desktop called EN_out. You should create this directory prior to running the script. Keep it open in Finder and see it being populated as the script runs.
    • I don’t see much if any point here for using a temporary directory solution as you need to grab the contents anyway, and there was no clean-up afterwards.
  2. For testing purposes as I have a lot of Evernote notebooks, most with lots of notes, I set a variable MAX_SIZE so that I only exported small notebooks.
    • It made my testing much quicker!
    • My advice would be to start with this set to a lower value to test it works and then increase it to something much larger when you want to run a full export.
  3. This one may be important to you or it may not. The current latest Event client app on Mac does not support AppleScript. You have to use the special legacy Evernote app if you have updated. You can have them alongside one another. If you are running an updated Evernote app, install the legacy app and you can keep the script as is. If you are still on the old client that supports AppleScript, change "Evernote Legacy" to just be "Evernote".
  4. I also added a check to skip empty notebooks.
    • No point in trying to process zero notes.

Give it a try and see how you get on.

1 Like

thanks very much. When I read your post, I had just started running another version of the script. As soon as it is complete, I will run your script.

I ran the script a few times.

  • error message below
  • please note that the script seem to work extremely well before the crash. The folder was being progressively populated.
  • what does MAX_SIZE refer to? number of notes ? size in MB? If I want to take out the MAX SIZE and zero count checks, how should I edit the script ?
    Should I simply take this out ?
if ((count of _notes) ≤ MAX_SIZE) and ((count of _notes) > 0) then
			set _path to EXISTING_OUTPUT_DIR & name of _notebook & ".enex"
			with timeout of 2 * 60 * 60 seconds

thanks again very much

What version of the Evernote app do you have?

For the notebook it gets to and fails on, any chance it is named named something that might be interpreted as a different file path? E.g. If it contained a forward slash.

Number of notes.

Don’t remove anything just follow my instructions and change it to a larger number. E.g. 999999

What you suggested would be insufficient in one respectand remove essential code too!

1 Like

No wonder my spouse says I am an idiot !

Evernote (web version ie not app store)
Version 7.14 (458244 Direct)
Editor: 69.3.10951 (15add1e)

I am reviewing the notebook names one by one. I already found names with “/” “,” and “→ ”
I will rerun the script after cleaning up the 500 notebook names.

thanks again !

So everything works now, all thanks to you. Praise sylumer !