Applescript create folder with properties

Hello,
This is my code:
Code Block AppleScript
on startButton_(sender)
        set folderDestination to choose folder
        log folderDestination
        log nameOfFolder
        tell application "Finder"
        make new folder at folderDestination with properties {name:nameOfFolder}
        end tell
    end startButton_

The idea ist to make a folder at the folder Destination (folderDestination) with the name of the folder (nameOfFolder).

This is the error from the console:
Code Block language
2021-03-13 09:28:02.844240+0100 Folder Creator[1571:39314] *** -[AppDelegate startButton:]: Finder got an error: Can’t make «class ocid» id «data optr0000000059FEE7F626C77C59» into type Unicode text. (error -1700)

But the log from the folder Destination and name did work:
Code Block language
2021-03-13 09:28:02.750713+0100 Media Folder Creator[1571:39314] file:///Users/name/Desktop/

and:

Code Block language
2021-03-13 09:28:02.753207+0100 Media Folder Creator[1571:39314] folderName123

The textfield in Xcode is connected to nameOfFolder.
Model Key Path: nameOfFolder

I do not know where the error is.
Thanks for your help.
Answered by Applefrage in 666538022
This solved the problem:
The problem is nameOfFolder is an NSString object, you have to bridge it to AppleScript by coercing it to text:
Code Block AppleScript
make new folder at folderDestination with properties {name:nameOfFolder as text}

But since you are already in the Cocoa world it would be more efficient to create the folder with NSFileManager.
Code Block AppleScript
on startButton:sender
set folderDestination to POSIX path of (choose folder)
log folderDestination
log nameOfFolder
set fileManager to current application's NSFileManager's defaultManager()
set {success, fmError} to fileManager's createDirectoryAtPath:(folderDestination & nameOfFolder as text) withIntermediateDirectories:false attributes:(missing value) |error|:(reference)
if success is false then log fmError's localizedDescription()
end startButton:

Here on stack overflow: https://stackoverflow.com/questions/66613102/applescript-create-folder-with-properties/66613251#66613251


Accepted Answer
This solved the problem:
The problem is nameOfFolder is an NSString object, you have to bridge it to AppleScript by coercing it to text:
Code Block AppleScript
make new folder at folderDestination with properties {name:nameOfFolder as text}

But since you are already in the Cocoa world it would be more efficient to create the folder with NSFileManager.
Code Block AppleScript
on startButton:sender
set folderDestination to POSIX path of (choose folder)
log folderDestination
log nameOfFolder
set fileManager to current application's NSFileManager's defaultManager()
set {success, fmError} to fileManager's createDirectoryAtPath:(folderDestination & nameOfFolder as text) withIntermediateDirectories:false attributes:(missing value) |error|:(reference)
if success is false then log fmError's localizedDescription()
end startButton:

Here on stack overflow: https://stackoverflow.com/questions/66613102/applescript-create-folder-with-properties/66613251#66613251


Applescript create folder with properties
 
 
Q