I’m using macOS Catalina and Xojo 2018 R1.1
I’m interacting with a folder with 3 items.
when i “ls -lah” the folder i got:
rw-r–r-- 1 alemac staff 1.5M Jan 28 19:00 # mytest.pdf
drwxr-xr-x@ 5 alemac staff 160B Mar 18 18:00 .
drwx------+ 11 alemac staff 352B Mar 18 17:59 …
rw-r–r--@ 1 alemac staff 681M Jan 28 18:59 mytest.dmg
rw-r–r--@ 1 alemac staff 495M Jan 28 19:01 mytest.rar
so 3 items: one pdf, one dmg and one rar file.
when I debug the “command” string variable:
for i=1 to pasta.Count
command = pasta.item(i).name
tipoDeArquivo = right(pasta.item(i).name,3)
if tipoDeArquivo = "dmg" then
f = pasta.item(i)
command = "hdiutil attach -noverify " + f.ShellPath
s.Execute(command)
exit
end if
next
command = pasta.item(i).name when i=1 mytest.rar
command = pasta.item(i).name when i=2 # mytest.pdf
command = pasta.item(i).name when i=3 NIL OBJECT EXCEPTION!
You might try 2019r3.1 using the new FolderItem.ChildAt method. If that also gives you a NOE, then I would report it. Just remember that ChildAt is zero-based.
I can’t tell you why, but for many years when using folderitem.item or folderitem.trueitem, you’ve had to test for Nil.
My guess has been that it’s a permissions thing (probably ACL) that prevents you from even knowing that there’s a file there. from your listing I can see that Mytest.dmg has ACLs present.
Try the following two lines in the terminal.
xattr -c mytest.dmg
chmod -755 mytest.dmg
These should reset all the permissions on the file. You may have to sudo first.
[quote=479635:@Sam Rowlands]I can’t tell you why, but for many years when using folderitem.item or folderitem.trueitem, you’ve had to test for Nil.
My guess has been that it’s a permissions thing (probably ACL) that prevents you from even knowing that there’s a file there. from your listing I can see that Mytest.dmg has ACLs present.
Try the following two lines in the terminal.
xattr -c mytest.dmg
chmod -755 mytest.dmg
These should reset all the permissions on the file. You may have to sudo first.
You meant System.DebugLog. A simple search in the documentation would spotted the error: I was 25% awake and forgot the Debug part. I checked FolderItem (to be sure it still exists in API2), but forgot to do so for DebugLog.
Sorry.
Also, as a Computer user, you know that asking indefinitely the same question will returns the same answer. Now that I slept for so many hours, I can spot the error. From your point of vie, you have copy/paste the provided code and get the error in Xojo. You alse spotted the error to System.Log (because you set "pasta.item(i).NativePath" between quotes). Dont you think ?
[quote=479690:@Emile Schwarz]And that is to that question I responded.
You meant System.DebugLog. A simple search in the documentation would spotted the error: I was 25% awake and forgot the Debug part. I checked FolderItem (to be sure it still exists in API2), but forgot to do so for DebugLog.
Sorry.
Also, as a Computer user, you know that asking indefinitely the same question will returns the same answer. Now that I slept for so many hours, I can spot the error. From your point of vie, you have copy/paste the provided code and get the error in Xojo. You alse spotted the error to System.Log (because you set "pasta.item(i).NativePath" between quotes). Dont you think ?
Once more, sorry for the error.[/quote]
system.DebugLog(pasta.item(i).NativePath)
out of bounds on first iteration (i=0)
[quote=479733:@Emile Schwarz]Why do you change that ?
The docs says:
If this FolderItem is a directory, Index is an element in a one-based array of FolderItems in this directory.
And you wrote earlier:[/quote]
This is the code:
for i=1 to pasta.Count
command = pasta.item(i).name
tipoDeArquivo = right(pasta.item(i).name,3)
if tipoDeArquivo = "dmg" then
f = pasta.item(i)
command = "hdiutil attach -noverify " + f.ShellPath
s.Execute(command)
exit
end if
next
when the for i=3 on this code above, I get a NIL OBJECT EXCEPTION!
I set three files in the “Dossier” folder, and pasta.Count = 4 (3 items and 1 invisible file).
The first file extension is “ore” (from the invisible file .DS_Store).
First run with a dmg file works fine. I checked what does hdiutil attach and added a dmg in the folder.
Nota: that (new) folder does not have invisible file(s).
I hope this help you.
The run crash sometimes, but not always.
[code] Dim pasta as FolderItem
Dim f as FolderItem
Dim command As String
Dim i As Integer
Dim tipoDeArquivo As String
Dim s As New Shell
pasta = GetFolderItem(“Dossier”)
for i=1 to pasta.Count
command = pasta.item(i).name
tipoDeArquivo = right(pasta.item(i).name,3)
if tipoDeArquivo = “dmg” then
f = pasta.item(i)
command = "hdiutil attach -noverify " + f.ShellPath
s.Execute(command)
exit
end if
next[/code]