Jump to content

dropbox-synced settings on two machines - dynamic relative file paths?


Recommended Posts

Hi there!

I have a bunch of simple shortcuts to open specific Dropbox folders, which I'd like to use across both my macbook and macpro. I have my settings synced, which works great for most of my matching folders (i.e. ~/Library), however the Dropbox location on the macpro is in an internal drive (/Volumes/DB HD/Dropbox) so it doesn't match the path on my macbook (~/Dropbox).

 

Is there a way to have conditional statement to trigger 1 of 2 provided paths, according to which machine is calling the workflow?

 

Thanks!!

Link to comment
8 hours ago, dterranova said:

Yes that's right I do.

 

When Alfred runs a workflow, the workflow's directory is the current working directory. So you can access any path in Dropbox using a relative path from your Alfred preferences instead of an absolute one. Say your Dropbox looks like this:

 

Dropbox/
    Alfred.alfredpreferences/
        workflows/
            user.workflow.BLAH-BLAH-BLAH/  <--- working directory
                you-are-here.py
    Documents/
    Photos/

 

When any workflow is run, you can access Dropbox/Documents at ../../../Documents

 

That might not work in all cases, but when it's possible, it's the simplest way, imo.

Edited by deanishe
Link to comment
  • 1 month later...

 

 

	set theComp to computer name of (system info)
	tell application "ChronoSync"
		if theComp contains "laptop" then
			open "~/archive/laptop to USB.sync"
		else if theComp contains "home desktop" then
			open "~/Documents/ChronoSync Documents/home <> USB.sync"
		else if theComp contains "work desktop" then
			open "~/archive/atu-childermas.sync"
		else if theComp contains "another computer" then
			open "~/ChronoSync Documents/another cs doc.sync"
		end if
		Trial Sync document 1
	end tell

 

Hi @dfay, I'm only just getting round to looking into this.  Haven't got too much time on my hands to dig around, hope you don't mind me asking for some pretty basic guidance? I'm a dumb dumb with applescript.

 

So, I see there's a NSAppleScript action. Is that what I should be using?

And do I drop it between the Keyword module and the Open File module, like so?

1453062247_ScreenShot2021-07-18at3_35_38PM.png.27af030564f6a748053f553f56eb321e.png

 

 

And as to the script you shared, I'm trying to understand how the variables work.

I guess in the first line you're creating theComp variable. But what's the part right after: "to computer name of (system info)" - should I be replacing that with anything or is that actual functional code that retrieves the machine's name?

As for the rest of the code, it's pretty clear. I guess since it already contains the "open" function, I shouldn't need the Open File module?

 

I know these are novice questions I could figure out by digging around, but figured I'd ask you first. Thanks a lot!!

 

 

 

 

Link to comment
On 6/6/2021 at 6:52 AM, deanishe said:

 

When Alfred runs a workflow, the workflow's directory is the current working directory. So you can access any path in Dropbox using a relative path from your Alfred preferences instead of an absolute one. Say your Dropbox looks like this:

 

Dropbox/
    Alfred.alfredpreferences/
        workflows/
            user.workflow.BLAH-BLAH-BLAH/  <--- working directory
                you-are-here.py
    Documents/
    Photos/

 

When any workflow is run, you can access Dropbox/Documents at ../../../Documents

 

That might not work in all cases, but when it's possible, it's the simplest way, imo.

Thanks @deanishe. I understand the relative path access, but how would that help me in the case of having conditional workflows?

I'm sure I'm missing something in what you're suggesting, if you can help connect the dots.

 

Link to comment
Quote

But what's the part right after: "to computer name of (system info)" - should I be replacing that with anything or is that actual functional code that retrieves the machine's name?

That's the AS code to get the computer name.  I'd run that line by itself in Script Editor to see how it works.  

 

I just used the open command but you could have it return different strings with the paths if you'd prefer.  

 

Presumably you'd need to change the tell as well - the open command is specific to ChronoSync.

 

See https://discussions.apple.com/thread/7761153

 

Edited by dfay
Link to comment
3 hours ago, dterranova said:

I understand the relative path access, but how would that help me in the case of having conditional workflows?

I'm sure I'm missing something in what you're suggesting, if you can help connect the dots.

 

Your problem is that Dropbox is in a different location on each machine, right?

 

But if you sync your workflows via Dropbox, you always know where the Dropbox folder is because Alfred will execute every workflow within your Dropbox folder. ../../../ (for example) will always be the path to your Dropbox root.

 

So to create a shortcut to a directory in your Dropbox, add a Keyword connected to a Run Script with Language = “/bin/zsh” and the Script /usr/bin/open "../../../Documents", for example.

 

Edited by deanishe
Link to comment
  • 7 months later...

Hi there! Almost a year later and embarrassingly I've progressed very little with this quest!

 

I'm sorry for such basic questions, but

1. Is this code right?

Quote

set theComp to computer name of (system info)
    tell application "Finder"
        if theComp contains "macbook" then
            open "~/Dropbox/Screenshots"
        else if theComp contains "macpro" then
            open "/Volumes/DB/Dropbox/Screenshots"
        end if
    end tell

 

2. How do I implement it?

This is what I've been playing around with so far:

1514379015_ScreenShot2022-03-18at02_01_28.thumb.png.49860d09a91e4185ea7a3f8ade22dbd9.png

 

 

and I'm sorry if it's documented somewhere already!

Bit snowed under and when I search I just get too overwhelmed with info as I'm already dealing with too many different softwares and their specific workflows.

 

p.s. I'm moving a lot of workflow/directory structure to dropbox to sync between the various machines, but need a single Alfred to open specific folders globally relative to the machine.

 

Edited by dterranova
Link to comment
  • 2 weeks later...
On 7/18/2021 at 7:22 PM, deanishe said:

Your problem is that Dropbox is in a different location on each machine, right?

 

But if you sync your workflows via Dropbox, you always know where the Dropbox folder is because Alfred will execute every workflow within your Dropbox folder. ../../../ (for example) will always be the path to your Dropbox root.

 

So to create a shortcut to a directory in your Dropbox, add a Keyword connected to a Run Script with Language = “/bin/zsh” and the Script /usr/bin/open "../../../Documents", for example.

 

Hi @deanishe!

I never got back to you about this as I got a little lost as to what happens in the Run Script. I'm beginner with this type of code.

But mainly, I wasn't sure how this solution could work since my dropbox is set up in different locations, so Alfred's prefs file doesn't have a "mirrored" path that can be used relatively.

 

Alfred prefs paths in both machines:

mac 1:   /Volumes/DB/Dropbox/AppPrefs/Alfred.alfredpreferences

mac 2:  /HD/Users/myusername/Dropbox/AppPrefs/Alfred.alfredpreferences

 

So calling ../../../../ wouldn't take me to the same location. Or would it??

And if so, what would I need to put in the Run Script to make it open a relative folder?

Happy to be pointed toward a link to read too! My searches are fragmented answers that I'm struggling to piece together.

 

Many thanks

 

 

 

p.s. this is still where I'm at currently!

1514379015_ScreenShot2022-03-18at02_01_2

Edited by dterranova
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...