Looking back at my last post, I just realised that the Mac version might not work properly. The shell path of a folder item in RealBasic is an 'escaped string'. This means that a file path such as /Users/markoxley/Desktop/Untitled Folder would end up as /Users/markoxley/Desktop/Untitled\ Folder (note the back slash before the space in 'Untitled Folder').
To fix this, we can implement a very simple function:
Sub UnEscape(value As String) As String
Dim s As String
Dim index as integer=0
while index<Len(value)
index=index+1
if mid(value,index,1)="\" then
if index<>Len(value) then
index=index+1
s=s+mid(value,index,1)
end if
else
s=s+mid(value,index,1)
end if
wend
Return s
End Sub
We would then replace the original subroutine with this:
Sub OpenFileWith(DocumentPath As FolderItem, ApplicationPath As FolderItem)
Dim ShellString As String
Dim sh As Shell=New Shell
#if TargetMacOS
ShellString="open -a '" + UnEscape(ApplicationPath.ShellPath) + "' '" + UnEscape(DocumentPath.ShellPath) + "'"
#elseif TargetWin32
ShellString=ApplicationPath.AbsolutePath + " " + DocumentPath.AbsolutePath
#endif
sh.Execute(ShellString)
End Sub
No comments:
Post a Comment