try
tell application “Finder” to set the source_folder to (folder of the front window) as alias
on error – no open folder windows
set the source_folder to path to desktop folder as alias
end try
the shell expects POSIX paths (slash separated)
and it’s much easier to work with absolute paths instead of using the cd command
try
tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
set the source_folder to path to desktop -- path to desktop IS an alias
end try
do shell script "touch " & quoted form of (POSIX path of source_folder & "temp123")
do shell script "ls " & quoted form of POSIX path of source_folder & " >" & quoted form of (POSIX path of source_folder & "temp123")
results an alias so the coercion as alias is useless
why not directly?
try
tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
set the source_folder to path to desktop
end try
set ls to (do shell script "ls " & quoted form of POSIX path of source_folder)
tell application "TextEdit"
activate
if (count documents) = 0 then make new document
set text of document 1 to ls
set name of document 1 to name of (info for source_folder)
end tell
Note: shell scripts work with POSIX paths, AppleScript works with HFS paths (colon separated)