Hello, hello,
I’m having a little problem concerning the automation of my media MacMini. While I am using PLEX for watching movies, series and online content. Since Plex uses a library system with fixed paths I want to create an “external” folder that is watched for conten by PLEX. Within the “external” folder are three more folders (“movie”, “pictures”, “music”) that will ensure that movies will end up in the movies section of PLEX, and so on.
(explenation of the structure:)
I now want, that whenever a media is connected to USB (except the always connected drives with fixed volumenames) it is mounted and a symlink is created to one of the three folders, depending on the content of the USB-media, and send a trigger to the PLEX Media Library to update itself.
I guess the workflow is something like:
It would be even better if the can be unmounted as well but that should not happen within the same script, but an standalone app i guess.
I know this is a lot, or maybe to much, but any help in realizing this would just be awesome
thx in advance for any suggestions and help and smoking heads
I’ve gotten closer, just a small step but still…
with:
list disks
I get a list of all mounted volumes.
With:
set USB_Drives_ext to {}
set USB to paragraphs of (do shell script "system_profiler SPUSBDataType -detailLevel basic")
repeat with i from 1 to (count of USB)
if item i of USB contains "Removable Media: Yes" then
set {end of USB_Drives_ext, i} to process_usb_device(i, USB)
end if
end repeat
on process_usb_device(i, USB)
set current_item to item i of USB
repeat until current_item = ""
set i to i + 1
set current_item to item i of USB
if current_item contains "Mount Point:" then
set mount_point to text (offset of ": " in current_item) through -1 of current_item
end if
end repeat
return {{mount_point}, i}
end process_usb_device
I get all mounted USB drives with its mount points.
Since the MacMini has 3 USB drives attached all the time, I can exclude them from a comparison and just need to look for the one, that differs from the 3 drives that are connected all the time. I guess I have to put the volume names of the internal and 3 USB drives in a hardcoded list and check the mount points against this list, haven’t I?
Any suggestions on how to do that?
BTW, the search was very helpful so far, all code is from posts here in the forum, but I’m, unfortunately, not a programmer who can figure it out by himself
on run
set drives to {"Macintosh HD"}
set all_drives to (list disks)
set new_drive to {}
repeat with v in all_drives
if v is not in drives then set new_drive's end to v's contents
end repeat
new_drive
end run
This gives me the name of the USB drive that is not specified as being connected all the time. Is it now possible to make an alias to a folder where I want it to?
on run
set drives to {"Macintosh HD"}
set all_drives to (list disks)
set new_drive to {}
repeat with v in all_drives
if v is not in drives then set new_drive's end to v's contents as alias
end repeat
tell application "Finder" to make new alias file at "Macintosh HD:Users:goeste:Filme" to new_drive
end run
… does now create an alias of each USB drive that is attached to the MacMini in the folder Movies.
I’m now just missing to send a trigger to the PLEX Media Library Manager to rescan (if it supports alises) and to remove the aliases after the drives are ejected.
on run
set PLEX_MS_delete to "/Users/goeste/Library/Application\\ Support/Plex/Plex\\ Media\\ Server.app/Contents/MacOS/Plex\\ Media\\ Scanner -c 9 -w"
set PLEX_MS_refresh to "/Users/goeste/Library/Application\\ Support/Plex/Plex\\ Media\\ Server.app/Contents/MacOS/Plex\\ Media\\ Scanner -c 9 -s -r -x"
set external to "Macintosh HD:Users:goeste:Movies:extern:"
set drives to {"Macintosh HD"}
set all_drives to (list disks)
set new_drive to {}
do shell script PLEX_MS_delete
repeat with v in all_drives
if v is not in drives then set new_drive's end to v's contents
end repeat
repeat with drive in new_drive
do shell script "ln -s " & POSIX path of drive & space & POSIX path of external & drive
end repeat
do shell script PLEX_MS_refresh
end run
old libraries get deleted, the drives mounted and scanned. AWESOME Now just some fine-tunig is needed, ie see if the files are movie-files or pictures.
Any help is highly appreciated