set AppleScript’s text item delimiters to {ASCII character 10}
set theFiles to (choose file of type {“org.openxmlformats.spreadsheetml.sheet.macroenabled”} with prompt “Please select a file or files” default location alias “YosemiteLacie256:Users:rondebruin:Desktop:” with multiple selections allowed) as string
set AppleScript’s text item delimiters to “”
return theFiles
I get this returned for example when I select two files
it’s not possible to get POSIX paths “in one go” with vanilla AppleScript (AppleScriptObjC can do it) but there is no reason to be scared of a simple repeat loop
set theFiles to (choose file of type {"org.openxmlformats.spreadsheetml.sheet.macroenabled"} with prompt "Please select a file or files" default location (path to desktop) with multiple selections allowed)
set thePOSIXFiles to {}
repeat with aFile in theFiles
set end of thePOSIXFiles to POSIX path of aFile
end repeat
return thePOSIXFiles
You may do the job with the same loop than the one used above but here is an answer without any loop.
(1) If you really want the pathnames separated by linebreaks you may use :
set theFiles to (choose file of type {"org.openxmlformats.spreadsheetml.sheet.macroenabled"} with prompt "Please select a file or files" default location (path to desktop) with multiple selections allowed)
set theHFSpaths to my recolle(theFiles, return)
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
(2) If you want a list of pathnames you may use :
set theFiles to (choose file of type {"org.openxmlformats.spreadsheetml.sheet.macroenabled"} with prompt "Please select a file or files" default location (path to desktop) with multiple selections allowed)
set theHFSpaths to paragraphs of my recolle(theFiles,return)
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mardi 25 août 2015 21:52:09
I really like to have the result is not a list, is there a way to get the result the same as i have first but only as posix files.
In VBA I like he result is not a list but a string
The string is returned in the variable theHFSpaths.
As Merdosoft products aren’t allowed on my machine, I tested with a slightly modified code.
-- set theFiles to (choose file of type {"org.openxmlformats.spreadsheetml.sheet.macroenabled"} with prompt "Please select a file or files" default location (path to desktop) with multiple selections allowed)
set theFiles to (choose file with prompt "Please select a file or files" default location (path to desktop) with multiple selections allowed)
set theHFSpaths to my recolle(theFiles, return)
--log theHFSpaths
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
set theFiles to (choose file of type {"org.openxmlformats.spreadsheetml.sheet.macroenabled"} with prompt "Please select a file or files" default location (path to desktop) with multiple selections allowed)
set thePOSIXFiles to {}
repeat with aFile in theFiles
set end of thePOSIXFiles to POSIX path of aFile
end repeat
set thePOSIXpaths to my recolle(thePOSIXFiles, return)
--log thePOSIXpaths
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 31 août 2015 18:42:56
This returns the file paths as a string one path per line
set theFiles to (choose file of type {"org.openxmlformats.spreadsheetml.sheet.macroenabled"} with prompt "Please select a file or files" default location (path to desktop) with multiple selections allowed)
set thePOSIXFiles to {}
repeat with aFile in theFiles
set end of thePOSIXFiles to POSIX path of aFile
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set thePOSIXFiles to thePOSIXFiles as text
set text item delimiters to TID
return thePOSIXFiles
Seems that I can’t get this working with the VBA MacScript function.
I need to add it in a separate script file for Office 2016 and run it in VBA with the new AppleScriptTask function I think.