#!/usr/bin/osascript
on convertListToString(theList, theDelimiter)
    set AppleScript's text item delimiters to theDelimiter
    set theString to theList as string
    set AppleScript's text item delimiters to ""
    return theString
end convertListToString

on isDirectory(someItem) 
    set filePosixPath to quoted form of (POSIX path of someItem)
    set fileType to (do shell script "file -b " & filePosixPath)
    if fileType ends with "directory" then return true
    return false
end isDirectory

on run argv
	set output to {}
	tell application "QSpace Pro"
		set selectedItems to selected item of window 1
		repeat with i from 1 to count of selectedItems
			set filePath to urlstr of item i of selectedItems
			set fileString to characters 8 thru -1 of filePath as string
			set end of output to (do shell script "sed 's/%20/ /g' <<< " & quoted form of fileString)
		end repeat
	end tell
	repeat with i from 1 to count of output
		set theItem to item i of output
		if isDirectory(theItem) then
			set item i of output to quoted form of (theItem & "/")
		else
			set item i of output to quoted form of theItem
		end if
	end repeat
	return convertListToString(output, "\n")
end run
