Hello everyone,
I am encountering an issue with running a simple AppleScript within a Batch Process in DT4. The script is intended to append text lines to a local file in my ~/Documents
folder, but after running the Batch Process, the file is not created and no data is written.
Here are the details of what I tried so far:
- I wrote a minimal AppleScript to append text to a file, for example:
on run {input, parameters}
set logFilePath to POSIX path of (path to home folder) & "Documents/faktury_log.txt"
do shell script "echo 'Test from Batch Process' >> " & quoted form of logFilePath
return input
end run
- I used Batch Process with manual input (Input Text) and with output from ChatGPT API feeding the script.
- In macOS System Preferences → Privacy → Automation, DEVONthink has permissions to control Finder and Terminal.
- The file does not exist before running Batch Process and is still not created afterward.
- The script does not create or write to files even when no input is passed — just a fixed text line.
- I verified the file path and directory exist, and permissions on
~/Documents
allow writing.
My goal is to append CSV lines extracted from documents into a local file or a DEVONthink record using Batch Process, but currently the AppleScript is either not executed or cannot write to disk.
Thank you for any advice!
My Apple Script
on run {input, parameters}
-- Ścieżka do pliku CSV
set csvFilePath to POSIX path of (path to home folder) & "Documents/faktury/faktury.csv"
-- Przygotuj tekst do dopisania: jeśli input to lista linii, połącz je nową linią
if (class of input) is list then
set csvText to ""
repeat with aLine in input
set csvText to csvText & aLine & linefeed
end repeat
else
set csvText to input & linefeed
end if
-- Dopisz tekst do pliku CSV (>> dopisuje, nie nadpisuje)
do shell script "echo " & quoted form of csvText & " >> " & quoted form of csvFilePath
return input
end run
As a matter of habit, things like logfilepath
should be a string before quoting it. So should csvFilePath
.
Also, you are using the wrong handler. It is not an on run
handler. You should be using a perform smart rule(theRecords)
handler as noted in the Automation > Smart Item Scripts section of the built-in Help and manual.
1 Like
on run {input, parameters}
set logFilePath to POSIX path of (path to home folder) & "Documents/faktury_log.txt"
set csvFilePath to POSIX path of (path to home folder) & "Documents/faktury/faktury.csv"
-- Convert paths explicitly to strings
set logFilePathStr to logFilePath as string
set csvFilePathStr to csvFilePath as string
-- Log input for debugging
do shell script "echo " & quoted form of (input as string) & " >> " & quoted form of logFilePathStr
-- Prepare CSV text
if (class of input) is list then
set csvText to ""
repeat with aLine in input
set csvText to csvText & aLine & linefeed
end repeat
else
set csvText to input & linefeed
end if
-- Append CSV text to file
do shell script "echo " & quoted form of csvText & " >> " & quoted form of csvFilePathStr
return input
end run
but it does’t work 
See my second paragraph.
And in this case, you’d want to use Script with Input/Output
not Apply Script
.
And here is a stripped down version of your script that works…
on scriptOutput(theRecord, theInput)
set logFilePath to (POSIX path of (path to home folder) & "Documents/Documents Indexed/log.txt") as string
if (class of theInput) is list then
set csvText to ""
repeat with aLine in theInput
set csvText to csvText & aLine & linefeed
end repeat
else
set csvText to theInput & linefeed
end if
-- Append text to file
do shell script "echo " & quoted form of csvText & " >> " & quoted form of logFilePath
end scriptOutput
2 Likes
Forgive me, but what would logfilepath
be if not a string?
set logFilePath to (POSIX path of (path to home folder))
log class of logFilePath
prints “*text*”. Which to me seems to indicate that logFilePath
is a string. Concatenating it with another string like in the script posting here shouldn’t change that.
I see this kind of coercion (or casts) frequently in AppleScript code. And often I don’t understand the reason for them – is that just a habit, or would the code really break if it were missing?
path to home folder
doesn’t return an HFS/APFS/POSIX path. It returns an alias, not a string.
(path to home folder as string)
makes it explicit, so adding as string
to the end of a concatenated path like the one shown covers the case in which someone forgot (or didn’t know) the value is an alias.
2 Likes
The input is always a string defined via the Set Script Input action.
That’s from the user’s code 
Incidentally, I thought you had mentioned the input could be a string or a list. Maybe the output can be a string, a list, or a record?
No, the input has been always a string.
A string is recommended. Or anything else (e.g. a number) that could be converted to a string as that’s what the Script Output placeholder uses in the end.
I’ll clarify the Script Output is always a string in the documentation.
ok, I’ve got it: „script with Input/Output” !! Thanks a lot 
1 Like