do shell command help

here is my code.

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

–do shell script "cd " & source_folder
do shell script “cd /Users/me/Desktop/;touch temp123”

do shell script “cd” & source_folder & “;ls >>/Users/me/Desktop/temp123”

i want the output of the ls command to be the files in the source_folder but in this case it get the ls output of the root of the HD.

Hi,

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")

that worked great.

Thanks
:smiley:

StefanK,

would you want to help me the rest of my script. here is the whole thing including the part you fixed before

this part works but I can’t hard code the path.

This part errors and says it can’t find the file

I would like to use the second option. Any ideas? the file is created and i can open it with text edit after the script ends

I’d like to repeat:

path to desktop

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)

i am confused.

How does that open the file? are you first opening textedit then creating the file inside textedit?

the script inserts the directory list into a TextEdit document directly

Sorry for that last post. i should have read your code closer. that works great. thanks