2
votes

I am trying to make functionality where I can right-click on a video file in OSX Finder, pressing Services and the name of my script, then MediaInfo would load in Terminal and video tag data would be shown (by MediaInfo). I got it working for files in my local drive. But it doesn't work for network drives because /Volumes is missing in the path and MediaInfo doesn't find the file.

I have put the following script as Run AppleScript in Automator, saved as Service ("Service receives selected files or folders in Finder" at the top part of Automator).

tell application "Finder"
    set theItems to selection
    repeat with itemRef in theItems
        set myfolder to (get folder of itemRef) as string
        set myfolder to POSIX path of myfolder
        set myfile to "'" & myfolder & (get name of itemRef) & "'"
    end repeat -- it will store the last filename in selection
end tell

tell application "Terminal"
    activate
    do script

    set size of window 1 to {1200, 1200}

    set cmd to "mediainfo " & myfile
    try
        if busy of selected tab of window 1 then error
        do script with command cmd in window 1
    on error
        do script with command cmd
    end try
end tell

So what to change in order to include /Volumes in the beginning of path when a network drive is in question?

3

3 Answers

1
votes

After some trial and error, this seems to be a working script for my purpose (running this script as a context menu item to show MediaInfo output in an enlarged new Terminal window):

tell application "Finder" to set theItems to selection
repeat with itemRef in theItems
    set myitem to "'" & POSIX path of (itemRef as string) & "'"
end repeat -- it will store the last filename in selection

tell application "Terminal"
    launch
    activate
    do script
    set size of window 1 to {1200, 1200}
    do script "mediainfo " & myitem in window 1
end tell
0
votes

You can get the Disk property of a Finder item, and then you can check if the Disk has the property local volume set to false.

I haven't tried this, but I think you'll have to address the item, as an item. (set theDisk to disk of item yourAlias).

This should at least in theory bring you a bit closer, I think for it to work, I reckon that you know what the posix path should then look like, with /Volumes/the network volume/the Path to/file and so on.

Finder also has the property startup disk, which I think you can use to compare drives with, if that is better for you.

Everything is in the dictionary of Finder in AppleScript Editor.

0
votes

Couple things, could not see why you were isolating the file name and then re-adding it. Using name of item sometimes includes the extension, but sometimes not. This especially is the case for network drives. And, don't put things in the Finder block that don't need to be there. This upper half works for me for selected files and folders, including on Network drives, including the Volumes/ in the posix path.

tell application "Finder" to set theItems to selection
repeat with itemRef in theItems
    set myitem to POSIX path of (itemRef as string)
end repeat -- it will store the last filename in selection