Choose file of type and POSIX path

Hi all

I use this to select for example a few files

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

“YosemiteLacie256:Users:rondebruin:Desktop:testscript 3.xlsm
YosemiteLacie256:Users:rondebruin:Desktop:Workbook1.xlsm”

I use VBA to play with this file paths and that is OK in Office 2011

But 2016 needs posix paths

Is there a easy way to get the posix paths of all selected files in one go with
return theFiles

Or must I convert each file at the time ?

Hi,

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 :wink:


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

Hi Stefan

Great this is much faster then do it in VBA after I got the result from the applescript.

Thanks for pointing me in the correct direction.

Have a nice day

How can i get it in the same format Stefan ?

Like this

“YosemiteLacie256:Users:rondebruin:Desktop:testscript 3.xlsm
YosemiteLacie256:Users:rondebruin:Desktop:Workbook1.xlsm”

In posix path then.

Try a few things but no luck (reason me)

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

Thanks for your reply Yvan

Bedtime for me so I check it out tomorrow after work.

Have a great day

Hi all

Thanks for all your help so far.

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

Thanks

My message gave the two formats.
The first script return a string with paths separated by a return character, the second one return a list !

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 31 aout 2015 10:37:33

Oops, sorry Yvan

I see now that I not test both, go test more this evening to get the result in VBA

Don’t worry.

You’re not the first and will not be the last being reading answers too fast.
I do that too from time to time :confused:

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 31 août 2015 16:40:44

Can you help me to get the result in posix paths Yvan with your string example

I don’t see what I may add.

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

#=====

The event log was :

tell current application
	path to desktop
end tell
tell application "Script Editor"
	choose file with prompt "Please select a file or files" default location alias "SSD 500:Users:<userAccount>:Desktop:" with multiple selections allowed
end tell
Résultat :
"SSD 500:Users:<userAccount>:Desktop: DJ Bazzie Wazzie.scpt
SSD 500:Users:<userAccount>:Desktop:270_012_205_Ko.png
SSD 500:Users:<userAccount>:Desktop:274_013_256_Ca.png
SSD 500:Users:<userAccount>:Desktop:274_013_256_Ca.png.pdf"

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 31 août 2015 17:28:00

Hi Yvan

I need posix paths in the string because Office 2016 VBA can’t work with : as seperator

Stefan’s code give the correct result but i only need it in a string instead if list

Try :

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

Hi Yvan and Stefan

Thanks for all your help

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.

I hate that change in Office 2016

Got the mail code also working again with this function(Mail and Outlook)
http://www.rondebruin.nl/mac/macmail/macmail2016.htm

Not nice that you nee a extra file and that it must be in a specific location

I go try it with the AppleScriptTask function in VBA and report it when it is working

Have a nice evening

Seems that I can’t get this working with the VBA MacScript function.

I was wrong, working now but need some more testing before I will publish it