Copy Google File Stream link to clipboard programmatically - alfred

With Google File Stream, you can right-click on a given file/directory in Finder and click "copy link to clipboard" from the contextual menu. Is it possible to recreate this programmatically, given the file's path?
My end goal is to create an Alfred workflow, so solutions involving bash/zsh, applescript, or python would all work.
I'm imagining something that looks kind of like filename | getfilepath...

Related

Can I open a file with `cd ~/../..` in Atom?

I opened up a large project in Atom. I'd like to travel to a file that is four folders deep into the project. Normally, I will go into the sidebar and flip open folders. Is there a way to open files programmatically? I'm thinking about the ability to use cd in terminal.
If you're trying to open a deeply nested file, try using the Fuzzy File Finder (Cmd-T on a Mac, Ctrl-T on Windows) to type in the name of the file. If you want to see it in the tree view after opening it, use the Reveal in Tree View feature (right click on the file tab and click Reveal in Tree View, or press Cmd-I with the file open).

Mac Textedit link to folder

Is there a way to create a link to a folder in a Textedit document?
Textedit native interface clearly cannot link to a folder. Finder, drag folder or alias to textedit document, then directly or through system prompts an image icon is created in the Textedit document to represent the folder (or file), but no link is created.
I came here looking for a way to open another TextEdit file using a hotlink. The previous ideas are definitely a step forward for me. While this is a slightly different question, my results may be useful here.
Using the file:// prefix on a full file path of the form:
file:///Users/myname/Documents/Personal/.../file.rtf
If the file is not already open, then the hotlink opens Finder and the file is highlighted.
If the file is already open, then the link takes me to the open file.
I have not found a way to get it to open a file that is not already open.
Results are a little differet when the link is to a folder instead of a file. Using the file:// prefix on a full folder path of the form:
file:///Users/myname/Documents/Personal/.../foldername/
Whether or not the named folder is already open, the hotlink opens Finder for the parent folder and the named folder is highlighted.
If the parent folder is already open, then the link goes to that open folder and highlights the named folder.
I have not found a way to get it to open the target folder, other than by naming a file that is in that folder. The special name "." does not work for that.
In Mojave 10.14.6, using hotlinks to other RTF files that open in TextEdit by default.
Here is a very time-consuming, but effective method to link to a folder from a Textedit document.
Add a file to folder (e.g., an image file), select the file;
Context menu 'Open with...' and select browser (Safari);
Edit browser address bar path to delete filename, leaving path to folder, and copy this address to clipboard;
In Textedit document, enter some text to link to folder (e.g., folder name);
Select text, press Command-K and paste folder path, save.
Now you have a Textedit link to the folder that will open in Finder! Maybe... using Automator and System Preferences Keyboard, this could be turned into a context menu command. Though I am noticing that in macOS Sierra 10.12.1 the use of customizations for context commands is flakey, TO PUT IT MILDLY... There has to be an easier way!
macOS Sierra version 10.12.1
I couldn't get Chrome nor Safari to allow me to select a file path. This is an updated version of Mark Stewart's response that worked for me.
Right click and select "get info" on the file you want to link to in the text document. (You can also select the file and hit "Command + i" to bring up the info dialog box)
Right click the file path in the "Where" field under the "General Section" and select copy
Go to the TextEdit document that you want to create the link in
Select the text you want to use as a link
Select text, press Command-K and paste folder path, but don't hit save yet.
Add the text "file:" without the quotes to the beginning of the link
Add a "/" character (not including the quotes) and the filename and the extension to the end of the link.
Now hit ok or save
I am sure someone could create a hot folder or right click menu that would build the path and precede it with file: and save it to the clipboard automatically.
macOS Catalina 10.15
The Open service should work for opening files and folders from paths in TextEdit and other text editors.
Two ways of getting a file or folder path into TextEdit:
For plain text documents: Simply drag'n'drop a file from Finder to your TextEdit document or
For RTF formatted documents: Select the file or folder in Finder, copy the file path (Command + Option + C), select your document in TextEdit, paste the path to the document (Command + V). That avoids the icon and pastes a text link to formatted and unformatted TextEdit documents.
The result will be something like this: /Path/To/File.ext for files or /Path/To/Folder for folders
To open a file or folder path from TextEdit with the Open service
Select the whole path in TextEdit (e.g. by left-click + hold + move or by moving the cursor with the help of the Arrow keys to the beginning or the end of the path, then select the path by pressing Shift + Arrow left/right keys, optionally in combination with Command or Option key)
Select the service Open from the Service Menu (Contextual or TextEdit menu).
Confirm the dialog Confirm Service: TextEdit wants to use the restricted Service “Open.” by pressing Run Service
You might also want to setup a keyboard shortcut for utilizing the Service Open (e.g. Command + Shift + O). It can be done in  > System Preferences > Keyboard > Shortcuts > Services > Text > Open. In the same Keyboard setting window tab, you can also activate All controls for dialog boxes, so that you can confirm Run Service by pressing Spacebar to get keyboard control for the whole task.
Automator:
workflow receives current 'files or folders' in 'Finder'.
Utilities:
'Copy to Clipboard'. Then
save service as:
'Copy Path'.
Finder: right click object (folder or file) and select service Copy Path.
TextEdit: edit link, type file: and paste path from clipboard.

How can I add a contextual menu item to all files on mac os x?

I want to add a contextual menu item to all files that allows to copy the file in a special path. And if possible, I want to add an icon to the menu item.
I'm working on mac os x.
This is very easy to accomplish. You will work in Automator and create a Service Workflow. (See info here.)
Since you tagged "Applescript", I assume you know Applescript. Just use an Applescript action within Automator to get the file path(s) and do what you want with them. You could also use the copy action to copy the files.

Changing the name of a Finder context menu item based on current selection using Applescript

When programming I find it convenient to use Finder to explore directories. In the past I would often find myself wanting an easy way to copy the complete path of the selected file or files to the pasteboard (clipboard) which is (as of OSX v10.8.2) a facility that Finder lacks. So being a programmer, I added the desired functionality by adding an Automator Workflow that launches a simple Applescript to the file context menu that appears when a selected file is right-clicked in Finder.
The script works great! It adds the desired functionality and is convenient to use. However, there is a piece of behavior that I'd like to add to the script that I haven't yet been able to figure out how to do. The name of the Finder context menu item that launches the Workflow is "Copy Filename" which is fine when there is only one file selected but when multiple files are selected I'd like the name menu item to change to "Copy Filenames" or perhaps "Copy "+(The # of selected files)+" Filenames".
So my question is this: How do I, using Applescript, dynamically set the name of an item in the file context menu that appears when a selected file is right-clicked in Finder based on the number of selected files?
There is some precedent for this type of behavior. It can be seen when copying selected files in Finder. If only one file is selected the copy menu item in the context menu will read, Copy "somefile.txt" but if five files are selected the copy menu item will read, Copy 5 Items.
You can’t. Well, you could, but it’s really gross and probably not worth the effort. The name shown in the menu is stored in an Info.plist file inside the workflow, so in theory you could write a monitor script that watches the Finder selection and twiddles that file appropriately, and then calls the magic function NSUpdateDynamicServices(), for which you’ll need AppleScriptObjC. (Or you could kill and relaunch Finder, but doing that every time you change the Finder selection would be, shall we say, impractical.)
An interesting enhancement request would be a way to name Service workflows such that the name reflects the selection, so you name your workflow, say, “Copy Path from %”, and the system would substitute “foo.txt” or “5 items” or what have you automatically.
It’s also worth noting that Finder actually does deal in full paths to some extent. Try dragging files into a plain text document -- you’ll get the paths. Or try copying and pasting into Terminal, which knows about the “furl” flavor on the pasteboard.

Access file name in Automator from Folder Action

I'm trying to create a simple Automator workflow that will prompt me for where to move and rename a PDF when I download one from the web. I want to use this for downloading my monthly financial statements.
I'm getting stuck at what I thought would be a simple problem: passing the name of the new file(s) from the Folder Action into the Automator workflow.
How is this done? I tried the "Get Specified Finder Items" action, disabling its input, and passed that to "Set Value of Variable" and in turn to "Ask for Conformation" so I could display the name of the file. It seems whatever I try, I cannot find how to pass the name of the newly downloaded files to the Automator workflow.
This seems like it should be simple. Does someone have an example of an Automator workflow triggered by a Folder Action that passes the files into the workflow?
For the life of me, I can never understand Automator. However I believe I can help in this case. The action you are looking for is called "Get Selected Finder Items" -- it is not intuitive, blame Apple for that.
To test out, I created a folder called "automator_action", then I started Automator (in Snow Leopard) and chose "Folder Action". This is the step you will need to figure out if you are using Leopard or earlier OS.
Next, I drag the "Get Selected Finder Items" (under Finder) over to the right pane, then I dragged the "Rename Finder Items" over and customized it. Finally, I saved the action and ready to test it out. You can see the picture presentation of my "script" here:
http://farm3.static.flickr.com/2590/3937364947_33b1a3ab45_o.png
I tested out the action by dragging a file into this folder and sure enough, the action renames it the way I intended. Dragging multiple files also works. Good luck.

Resources