Only move to drive when connected

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Only move to drive when connected Tue Sep 20, 2011 7:03 pm • by SkY
Hi!

I have a rule that moves all my epsiodes to there correct folder on my external drive.
rule:
name contains how.i.met.your.mother.s07 > move to folder season 7 (on external drive)

My external drive isn't always connected so I get this error:

2011-09-21 00:59:12.640 hazelworker[1776] [Error] Move failed: Could not move file How.I.Met.Your.Mother.S07E02.720p.HDTV.X264-DIMENSION.srt from folder /Users/User/Movies to folder /Volumes/SERIES I/Series/How I Met Your Mother/SEASON 7.
2011-09-21 00:59:20.646 hazelworker[1776] How.I.Met.Your.Mother.S07E02.720p.HDTV.X264-DIMENSION.srt: Rule How I Met Your Mother S07 matched.
2011-09-21 00:59:20.672 hazelworker[1776] Error creating FSRef for path /Volumes/SERIES I/Series/How I Met Your Mother/SEASON 7: -43 - File not found


Is there a way to only run this rule when a certain Volume is connected?
SkY
 
Posts: 6
Joined: Tue Sep 20, 2011 8:35 am

Re: Only move to drive when connected Wed Sep 21, 2011 10:41 am • by SkY
Found it

Code: Select all
DOCSDIR="/tmp"
if [ -d "$DOCSDIR" ]
then
        contected=0
else
        contected=1
fi

exit $contected
SkY
 
Posts: 6
Joined: Tue Sep 20, 2011 8:35 am

Re: Only move to drive when connected Wed Sep 21, 2011 10:58 am • by Mr_Noodle
The script isn't needed. If a rule fails because the drive is offline, Hazel will retry until the drive comes online.

In 3.0, I will be making this more efficient (this should be in the next beta patch) but the overall behavior is the same.
Mr_Noodle
Site Admin
 
Posts: 11247
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Only move to drive when connected Tue Nov 15, 2011 11:00 pm • by tc60045a
You can run embedded AppleScript to connect your drive -- and alert if not available. This works fine in Hazel.

Code: Select all
tell application "Finder"
   activate
   if not (exists disk "cserver") then
      mount volume "nfs://192.168.1.13/cserver"
      delay 5
   end if
   if not (exists disk "cserver") then
      display alert "The readyNAS server is not connected - I tried twice!"
      return
   end if
   
   --make sure mserver is awake; try once, wait, then fail if no dice
   if not (exists disk "atvInbox") then
      mount volume "afp://192.168.1.14/atvInbox"
      delay 5
   end if
   if not (exists disk "atvInbox") then
      display alert "The media laptop is not connected - I tried twice!!"
      return
   end if
end tell
tc60045a
 
Posts: 9
Joined: Tue Nov 15, 2011 10:55 pm

Re: Only move to drive when connected Sat Mar 25, 2017 9:14 am • by johseb
@Mr_Noodle I'm not seeing the behaviour you described in your previous post.

I have a simple rule that 1) rename a matching file and 2) move the renamed file to a destination folder on a USB external drive.

If the drive is not connected and mounted the file is renamed but obviously it is not moved to the destination folder. When I attach the drive the now renamed file stays in the source folder and it is not moved as per your post (I waited several minutes and even run rules manually).

(Hazel 4.0.9 on OSX 10.11.6)
johseb
 
Posts: 1
Joined: Sat Mar 25, 2017 8:57 am

Re: Only move to drive when connected Mon Mar 27, 2017 10:51 am • by Mr_Noodle
Go to the "Info" section and click "View Log". Search for the file in question and post or email the relevant logs.
Mr_Noodle
Site Admin
 
Posts: 11247
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Only move to drive when connected Thu Aug 31, 2017 7:21 am • by chase.turner
@Mr_Noodle

Would either of these two optional enhancements to Hazel address the issue in this thread?

a) A Hazel condition whose action is to return "True" if a named [^1] volume is mounted (or false if not mounted) would satisfy this use case by allowing an end user to add the pre-condition to their Hazel rule? or;

b) Hazel implicitly notices the destination path begins with /Volume and hence, Hazel triggers the rule if and only if the path is mounted before executing the rest of the end-user's condition triggers to move the file.

For either of the options above, Hazel's "Show rule status" now has the additional complication of signaling to the user their Rule is matched, but execution will fail on account of the /Volume/... path not mounted.

NOTES:
[^1]Options to choose how to name the mountable medium is useful here. That is, an end-user can select whether they want Hazel to reason about a path, versus a specifically DUID for a mounted storage device. For example, if there are two USB sticks named "myUSB", first one added will be mounted as "/Volumes/myUSB" and the second one inserted would be mounted as "/Volumes/myUSB1". No way for Hazel to read the end-user's mind in that circumstance, but for those who understand the distinction, they could tweak the Hazel rule to fire on a specific mounted DUID of the mounted device.
chase.turner
 
Posts: 2
Joined: Thu Aug 31, 2017 6:57 am

Re: Only move to drive when connected Thu Aug 31, 2017 10:43 am • by Mr_Noodle
After the first failure, Hazel will mark the drive as being unavailable and will not attempt to run the rule after that until the drive is re-mounted. I can look into pre-checking though because of complications like aliases and symlinks, it might be the case where the only reliable way is to try the operation itself.
Mr_Noodle
Site Admin
 
Posts: 11247
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Only move to drive when connected Wed Aug 01, 2018 4:27 pm • by chase.turner
Mr_Noodle wrote:After the first failure, Hazel will mark the drive as being unavailable and will not attempt to run the rule after that until the drive is re-mounted. I can look into pre-checking though because of complications like aliases and symlinks, it might be the case where the only reliable way is to try the operation itself.


Friendly ping here to ask if there is the possibility of considering this feature a year on from this post. Reason : when I'm out of my house with my laptop, it is not uncommon during my workday to collect a variety of documents during the day. When I return home where I can connect -- via my Thunderbolt to various drives -- I am manually copying these documents out of my "holding" folder of the day so that they are now archived. And in some cases, I am mounting an encrypted DMG once a month to update them with contents from the "holding" folder on my laptop's desktop.

To the best of my knowledge, all drives have a unique ID, and (hopefully) there is a general event trigger when a drive is mounted such that Hazel would notice a drive matching a destination in a trigger action is now mounted and the workflow can run to drain files from my "holding" folder on my laptop to their destinations.
chase.turner
 
Posts: 2
Joined: Thu Aug 31, 2017 6:57 am

Re: Only move to drive when connected Thu Aug 02, 2018 10:30 am • by Mr_Noodle
If it isn't triggering at all, there might be another issue, in which case, you should email in with your logs and any relevant info.

Also, have you considered doing the rename after the move?
Mr_Noodle
Site Admin
 
Posts: 11247
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Only move to drive when connected Thu Aug 02, 2018 11:25 am • by TheWart
Just wanted to chime in and say that my rule to move installation files (.DMG) to an external drive when present works as expected in macOS 10.13.6 and Hazel 4.2.8. I'll get a notification that the file could not be moved if the drive is not connected, but the next time the drive connects Hazel will move the file.

I have not checked logs to see exactly when this happens, but the rule is pretty vanilla and without AppleScript if someone needs reference.

Also, the staging folder is on Dropbox synced locally to my Mac, if that makes a difference to anyone.

https://www.dropbox.com/s/hjr8zyhdlw0arvc/Screenshot%202018-08-02%2010.21.55.png?dl=0
TheWart
 
Posts: 5
Joined: Sat Mar 12, 2016 11:14 am


Return to Support

cron