I'm trying to build a simple JavaScript for Automation script to add the currently playing track in iTunes to a particular playlist.
I have the playlist name stored as a string, var playlist.
The JXA Library add method says the following:
add method : add one or more files to a playlist
add list of file : the file(s) to add
[to: location specifier] : the location of the added file(s)
→ Track : reference to added track(s)
What I can't figure out is what to put for the [to: location specifier] part to specify a playlist.
I tried:
playlist = 'Queue'
iTunes = Application('iTunes')
iTunes.add(iTunes.currentTrack, {to: iTunes.playlists[playlist]})
But I get "Error -1708: Message not understood."
add doesn't do what you want here (add is used primarily for importing files outside of iTunes into the application, that's what the location specifier refers to).
You want to use the duplicate method on the track you want to "duplicate", copying it "to" the destination playlist. This code snippet works for me:
var iTunes = Application('iTunes');
var playlist = iTunes.playlists['Queue'];
iTunes.currentTrack().duplicate({to:playlist});
Related
When you get the tracks from the global playlist from Itunes/Apple Music with Applescript how do you get only filetracks
e.g
I can do
return tracks of playlist 1
but that will return all tracks including those on the cloud, I only want the one that are actually stored on the harddrive
I see you can use a filter but how do I filter to only retrieve filetracks ?
tell application "Music" to return file tracks of playlist 1
Robert's answer is almost right.
tell application "Music" to return file tracks of playlist 1
works for most instances of the AppleScript class playlist, but not for all of them, because the element file tracks is only declared in various sub-classes, but not in the playlist class itself.
For example, it does not work, if the playlist happens to be a radio tuner playlist or an audio CD playlist. They don't declare the file tracks element.
So before calling file tracks of, you should check the class property of the playlist to ensure your playlist object actually has a file tracks collection.
I'm trying to create a Numbers' document and then export it to pdf, but my main issue is that the document is created in iCloud and I cannot delete it. To make this new document at a custom location, I'm using make new document at, but I can't get the location specifier correct.
I tried to use a path:
set downloads to path to downloads folder
But I get an error, "can't make alias "path" to type location specifier". And if I try this:
set myDocument to make new document at end of downloads
I get another error Can't obtain alias "Users:username:Downloads"
I don't understand how I can simply create my document at a specific location...
You're mixing apples with oranges. The "location" here is merely the front-to-back position among other similar entities, such as documents / windows. You specify the path on disk when you save the document in a later step.
As far as I see there is only one type of media field which can hold every type of media (image, video, pdf etc.) Is there a way to restrict the media type, so that the field only accepts images and no other filetypes? Because when I allow the field to hold multiple files the array will hold images, video and files. I search for a solution how I can restrict the data types for this field.
You can deal with that by updating the upload function of the upload plugin.
Please for that you will have to check how the extensions folder work.
📚Documentation here: https://strapi.io/documentation/3.0.0-beta.x/concepts/concepts.html#extensions
And after you will have to find the path of the file you want to update.
It will be this one https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-upload/controllers/Upload.js
So you will have to create an empty file at the same path in the extension folder.
It will be ./extensions/upload/folder/Upload.js
module.exports = {
};
In this file you will have to create the function you want to update/override.
It will be this function https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-upload/controllers/Upload.js#L12
So you have to copy this function and past it in your extensions file.
When it's done you can modify the function as you want.
Here in the function https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-upload/controllers/Upload.js#L27 you can see the var files contain all your files, you can simply add your code to test the type of your files.
In macOS, I want a folder action to trigger when I place a new file in that folder. The action should grab the filename, not including the path, and use that as the subject, and then attach the file to an email message and send it. Ideally, this would happen behind the scenes as I don't need to see the activity.
I created an Automator script that can grab the file, extract the name, create and send the file. But it's a bit of a kludge. Once I set a variable to the filename, I lose the attachment and have to get the finder item again. Also, it's not working as a Folder Action which is what I really need.
The Automator includes these steps:
Get Specified Finder Items
Get Folder Contents
Filter Finder Items -- I'm only interested in specific files
Set Value of Variable
--path
Run Shell Script -- extract only the filename without the extension
--basename "$#" .pdf
Set Value of Variable
--fileName
New Mail Message
--Subject: fileName
At this point I no longer can attach the specified file because Automator has 'lost' it, so I have to start over with the Get Specified Finder Items, Get Folder Contents, Filter Finder Items, Add Attachments to Front Message. Finally, Send Outgoing Messages.
What I want to happen is when I place a certain file into a directory, the Folder Action triggers, it looks at the file, and if it meets the filter criteria it emails the file, using only the filename without the extension as the Subject.
Create an Automator document type that is a folder action, and attach it to the desired folder. Items added to the specified folder will be passed on to the workflow, so you don’t need to use additional actions to get them.
You are already saving the filtered item paths in a variable, you just need to get them back for the Mail action:
Folder Action receives files added to { wherever }
Filter Finder Items
Set Value of Variable { Variable: path }
Run Shell Script
Set Value of Variable { Variable: fileName }
Get Value of Variable { Variable: path } (ignore input)
New Mail Message { Subject: fileName } (passed files are attached)
Automator workflows are designed to work with multiple input items as a batch; dealing with items one at a time would require a script or third party action such as Dispense Items Incrementally.
I'm trying to make my add-on save bookmarks in it's own bookmark folder.
This function created the desired folder, but I want it to return the id of the existing folder instead of forever making millions of new ones if it can find it by name:
function special_bookmark_folder()
{
menuFolder = bmsvc_service().bookmarksMenuFolder;
// <Try and find the bookmark folder here!>
return bmsvc_service().createFolder(menuFolder, ":: Bookmarkr ::", bmsvc_service().DEFAULT_INDEX);
// else return id of existing folder if it's found here
}
You have to use the Places query APIs, which isn't the most straightforward task. Thankfully there is an example with exactly what you want