Like Change Agent I can’t get the given code to work when I try to apply it to a volume name “Macintosh HD”.
-- kMDItemKind is an localized string
-- Folder should be Map if your system is Dutch for instance
--do shell script "mdfind -onlyin '/Volumes/Macintosh HD/' -0 'kMDItemKind = \"Dossier\" && kMDItemFSName = \"_X28544Æ’\"' | xargs -J % open \"%\""
# Fails with the error
(*"The files /Volumes/Macintosh, /HD/Users/Important/pour, and /ebay/_X28544Æ’ do not exist." number 1*)
As I am curious I decided to split the instruction in two components.
1 - the one locating the folder
I starting searching a resource from which I may grab the localized string kMDItemKing.
As I don’t know where it is stored with this name, I searched for the string Folder and I got one (I guess that there are other ones but one is sufficient.
(path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle"
set Folder_loc to localized string "Folder" from table "InfoPlist" in bundle (result as «class furl»)
--set theFolder to do shell script "mdfind -onlyin '/Volumes/Macintosh HD/' -0 'kMDItemKind = \"Dossier\" && kMDItemFSName = \"_X28544Æ’\"'"
set theFolder to do shell script "mdfind -onlyin '/Volumes/Macintosh HD/' -0 'kMDItemKind = \"" & Folder_loc & "\" && kMDItemFSName = \"_X28544Æ’\"'"
--> "/Volumes/Macintosh HD/Users/Important/pour ebay/_X28544Æ’"
As this first part behaves well I understood that the culprit is the second part.
2 - the one trying to open the extracted folder.
# Example in the man for open :
do shell script "open '/Volumes/Macintosh HD/Applications/'" # WORKS !
# Define the path as it is extracted by part 1
set theFolder to "/Volumes/Macintosh HD/Users/Important/pour ebay/_X28544Æ’"
# Add the ending slash to match the man example
if theFolder does not end with "/" then set theFolder to theFolder & "/"
# I tried :
--do shell script "open " & quoted form of theFolder # which failed
# I tried also the hardcoded version :
do shell script "open '/Volumes/Macintosh HD/Users/Important/pour ebay/_X28544Æ’/'" # which failed too
(*error "sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file" number 2*)
I’m curious but I’m far to be patient so I decided to drop Shell Script the second part and use the Finder because my attempts to use System Events failed.
(path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle"
set Folder_loc to localized string "Folder" from table "InfoPlist" in bundle (result as «class furl»)
set thePaths to do shell script "mdfind -onlyin '/Volumes/Macintosh HD/' -0 'kMDItemKind = \"" & Folder_loc & "\" && kMDItemFSName = \"AppleScript\"'"
--> "/Volumes/Macintosh HD/Users/Important/PDFs/ Apple ƒ/AppleScript/Volumes/Macintosh HD/Users/yvankoenig/Desktop/Documents partagés/AppleScript/Volumes/Macintosh HD/Users/Important/Téléchargements/ThisService Starting Points/AppleScript/Volumes/Macintosh HD/Users/Important/Téléchargements/thisService ƒ/ThisService-2.0.2/ThisService Starting Points/AppleScript"
set thePaths to items 2 thru -1 of my decoupe(thePaths, "/Volumes/")
repeat with apath in thePaths
set thePaths to POSIX file ("/Volumes/" & apath)
tell application "Finder" to open thePaths
end repeat
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
Does the job but I was forced to add some instructions because when several folders are found, mdfind return their pathnames with no separator.
I used /Volumes/ to split the flow in valid components.
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) lundi 23 mai 2016 21:43:04