Monday, October 22, 2018

#1 2018-05-15 03:59:25 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Changing Alias Original based on whether a Volume Exists or not

Hi All,

I currently have this script written to accomplish my goal, but it only finishes successfully when the volume in question exists. For some reason, if it doesn't exist the script errors out. If I change the localSessions variable to cloudSessions, just like the statement when the volume doesn't exist, it works, as long as the volume still exists...very strange. Anyone know why this is happening? Script is below. I'm sorry I couldn't explain further, but it will make a lot more sense when you look at the code smile

Applescript:



set theAlias to (path to desktop as text) & "Protools Sessions"
set localSessions to "Samsung_T3:Protools Sessions"
set cloudSessions to "Google Drive:My Drive:Protools Sessions"
tell application "Finder"
   if exists "Samsung_T3" then set original item of file theAlias to localSessions
   if not (exists "Samsung_T3") then set original item of file theAlias to cloudSessions
end tell

Offline

 

#2 2018-05-15 11:14:22 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

You're asking if a string exists, not a file or folder -- you can't just use paths or names.

Try something like this:

Applescript:

set theAlias to (path to desktop as text) & "Protools Sessions"
set localSessions to "Samsung_T3:Protools Sessions"
set cloudSessions to "Google Drive:My Drive:Protools Sessions"
try
   set theOriginal to localSessions as alias
on error
   set theOriginal to cloudSessions as alias
end try
tell application "Finder"
   set original item of file theAlias to theOriginal
end tell


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2018-05-16 09:28:10 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

Hi Shane,

Thank you so much, that looks very logical, but unfortunately still produces the same error I had before. For some reason, it seems to be dependant on whether or not the Samsung volume exists. If I switch the localsessions and cloudsessions variables around, while the volume is present, it changes the alias original for either of them without issue. But as soon as the Samsung harddrive disappears, it throws an error that it can't set the alias to the samsung_t3:Protools Sessions as alias. So strange...I even tried surrounding the set statements with try blocks with no luck...thoughts?

Offline

 

#4 2018-05-16 10:31:21 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

So what happens if you run the script as posted and the Samsung drive isn't mounted?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2018-05-17 04:06:19 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

both your script and my original script give me this message if the samsung drive is not mounted. If it is mounted, I can set the original to either cloudSessions or localSessions without a problem and it changes the alias files correctly, with both scripts.


error "Finder got an error: Can’t set original item of alias file \"Protools Sessions\" of folder \"Desktop\" of folder \"roccofiorentino\" of folder \"Users\" of startup disk to \"Google Drive:My Drive:Protools Sessions\"." number -10006 from original item of alias file "Protools Sessions" of folder "Desktop" of folder "roccofiorentino" of folder "Users" of startup disk

Also, as a sidenote, how do I subscribe to a topic so that macscripter notifies me by email? There used to be a checkbox to do this but now I'm not seeing it...

Offline

 

#6 2018-05-17 05:42:24 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

rfscripter wrote:

both your script and my original script give me this message



I don't think so. That message is showing \"Google Drive:My Drive:Protools Sessions\" as a string, which is what your original code tried to use. If you run my code, which uses an alias, you can't get an error message like that.

Please run the script as posted and report what happens.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2018-05-17 07:34:02 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

When looking at your script I would agree with you. But I guess the computer doesn't think like us, because your script gives me the same error, with a little more text before it. Both this error and the one before were copied directly from the script log. The dialog that appears when running either script does not show the \ in the folder path, not sure why. The error from your script is:

tell application "Finder"
    set original item of file "Macintosh HD:Users:roccofiorentino:Desktop:Protools Sessions" to alias "Google Drive:My Drive:Protools Sessions:"
        --> error number -1728 from original item of alias file "Protools Sessions" of folder "Desktop" of folder "roccofiorentino" of folder "Users" of startup disk
Result:
error "Finder got an error: Can’t set original item of alias file \"Protools Sessions\" of folder \"Desktop\" of folder \"roccofiorentino\" of folder \"Users\" of startup disk to alias \"Google Drive:My Drive:Protools Sessions:\"." number -10006 from original item of alias file "Protools Sessions" of folder "Desktop" of folder "roccofiorentino" of folder "Users" of startup disk

Offline

 

#8 2018-05-17 08:31:39 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

I'm wondering if the error has something to do with path conversions? I've tried different paths and conversions with no luck yet.

Offline

 

#9 2018-05-17 08:36:12 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

The important difference is that that version confirms that the alias was successfully created. Not that it's going to help you, unfortunately. Error -10006 is errAEWriteDenied, and I'm guessing the script is failing because the Finder doesn't like something about the Google drive.

Can you make the change manually in the Finder at all?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#10 2018-05-17 08:57:10 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

Hi Shane,

Yes, I can make the change manually if I select a new original. But I need the alias to change based on whether or not the drive exists, so that it doesn't prompt me to "fix" the alias when the drive doesn't exist. It may not like the google drive volume because it's a virtual network drive (google's application Google File Stream is creating it), but that doesn't seem to matter because I just re-confirmed that if the samsung drive is connected, it will set the original to google or samsung, depending on the variable I replace. But as soon as I eject that volume, it won't change the original path, even if it's a path unrelated to the task. For example, I changed both local and cloud session variables to the desktop folder separately and it wouldn't map the alias there either, until I connected the samsung again. Very strange...

Offline

 

#11 2018-05-17 09:30:16 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

perhaps you could try a different approach. Make alias files for both drives, and then swap and/or rename the files depending on which volume is mounted.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#12 2018-05-21 02:42:36 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

Yes, I could do that for now, I guess, but I feel like there's something really simple that's stopping the current script from working, and I would like to still try and figure that out. smile I'm one of those people where when something doesn't work correctly I stand play with it until does. haha Anyway, I'll try that for now and see what happens. My only fear with that is that if I'm trying to access that alias at the exact time when it's replacing/renaming, etc. I'm not sure what the finder would do/how it would deal wit that. If you think of anything in the meantime please let me know.

Thanks so much,

Rocco

Offline

 

#13 2018-05-31 08:08:49 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

Ok...so I've now converted this script to using the file manager library, because it's awesome smile I'm also now replacing the alias file with another one specifically for each task. However, it's still having a problem replacing it seems. If no alias is in the destination, the script executes perfectly. But as soon as that file already exists, it seems like it replaces it, but the alias original never changes. See script below:

Applescript:



use scripting additions
use theLib : script "FileManagerLib" version "2.1"

set theAlias to (path to desktop) as text
set cloudSessions to (path to home folder) & "Pro Tools Sessions Shortcuts:" & "Cloud:" & "Protools Sessions" as text
set localSessions to (path to home folder) & "Pro Tools Sessions Shortcuts:" & "Local:" & "Protools Sessions" as text
property samsung : "Samsung_T3"

tell application "Finder"
   if exists samsung then
       copy object localSessions to folder theAlias with replacing
       
   else
       copy object cloudSessions to folder theAlias with replacing
       
   end if
end tell

Offline

 

#14 2018-05-31 08:18:07 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

Leave the Finder out of it:

Applescript:

if exists object samsung then
   copy object localSessions to folder theAlias with replacing
else
   copy object cloudSessions to folder theAlias with replacing
end if


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#15 2018-05-31 09:41:42 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

Ok, cool. Didn't know I didn't need finder to be able to check if the volume existed or not. But still, same thing happens. If the file is already present, it won't change the original it points to. Is there a way to make the file manager output what it's doing to the script log? Maybe it's not copying for some reason when the file is there, even though I'm specifically telling it to replace? I'm stumped...

Offline

 

#16 2018-06-01 12:50:11 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

If the copying fails, an error should be thrown.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#17 2018-06-01 08:08:44 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

nope, no error......just doesn't change the original location  unless the file doesn't exist in the destination folder. Anything you can think of?...

Offline

 

#18 2018-06-01 08:44:18 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

You could try deleting the destination file first. Then you can see if the copy worked easily enough.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#19 2018-06-01 09:35:06 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 83
Website

Re: Changing Alias Original based on whether a Volume Exists or not

I did, that's what I'm saying. When I delete the destination file before running the script, it works every time, and copies the correct alias file. But if the file is already there, the original of the new alias doesn't change. It's almost as if because it's an alias that makes it different somehow from a normal file, and thus something gets weird when replacing attributes....I don't know, that's the only thing I can think of. Or are you saying delete the file every time inside the script?

Offline

 

#20 2018-06-02 12:23:57 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Changing Alias Original based on whether a Volume Exists or not

rfscripter wrote:

Or are you saying delete the file every time inside the script?



Exactly.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)