Getting TasksFile out of Link object? #3627
-
|
I wonder if it is possible to get TaskFile out of Link object in Ideally i would like to do something to this extend:
where property("project") would return Link or atleast
Is it possible in current version? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 28 replies
-
|
Hi, I've read your question several times, and am not confident that I understand it.
|
Beta Was this translation helpful? Give feedback.
-
tl;drNo, it's not possible in a reasonable amount of time, using Tasks 7.21.0 DetailsI've spent more than 45 minutes on this today - half an hour of which was after receiving the sample files, for which thanks again. My conclusion is that the request functionality is not currently possible in Tasks, unless someone is already familiar with the Obsidian API. What next?You are welcome to create a Feature Request on the Tasks plugin, if you would like this to be considered for implementation in future. If I were less unwell I might have been able to make some progress, but I really should focus on getting better. |
Beta Was this translation helpful? Give feedback.
-
|
For future programmer reference, someone wrote up some of the ingredients of this in: #93 (comment) |
Beta Was this translation helpful? Give feedback.
-
|
@janserbus @claremacrae I've been working on similar thing, so maybe it's helpful to add my ideas here. I've implented a simple The result is this script: String.prototype.asFile = function() {
require("obsidian/app");
if (typeof app === 'undefined') {
console.warn('Obsidian app instance not available');
return null;
}
// Extract the actual filename from the wiki link
// Handle both [[FileName]] and [[FileName|Display Text]] formats
const linkMatch = this.match(/\[\[([^|\]]+)/);
if (!linkMatch) {
console.warn('Invalid wiki link format:', link);
return null;
}
const fileName = linkMatch[1].trim();
// Find the file in the vault
const file = app.metadataCache.getFirstLinkpathDest(fileName, '');
if (!file) {
console.warn('File not found:', fileName);
return null;
}
// Get the file’s metadata (frontmatter)
const metadata = app.metadataCache.getFileCache(file);
const frontmatter = metadata?.frontmatter || {};
return {
get properties() {
return frontmatter;
},
/**
* Check if the file has a specific property in its frontmatter
* @param {string} propertyName - The name of the property to check
* @returns {boolean} True if the property exists, false otherwise
*/
hasProperty(propertyName) {
return propertyName in frontmatter;
},
/**
* Get the value of a property from the file's frontmatter
* @param {string} propertyName - The name of the property to retrieve
* @returns {any} The property value, or undefined if not found
*/
property(propertyName) {
return frontmatter[propertyName];
}
}
};And I'm using it with my Tasks code like this: By any means this is not neat or efficient but it definitely works and I'm hoping to work some more on it. @janserbus the only things I've no exposed are the (frontmatter) properties, but it's trivial to also expose file details. |
Beta Was this translation helpful? Give feedback.
-
|
I have made a test build of a possible implementation of this, to allow experimentation and feedback. See: See that link for how to instal it, and how to use it. |
Beta Was this translation helpful? Give feedback.
-
|
My own feedback on the experiment in #3639: Because @mnaoumov said not to pollute string, I ended up with a new method than this: But this is not important enough to be a breaking change - so I still want plain |
Beta Was this translation helpful? Give feedback.
-
|
I'm interested in this feature! I was wondering if this was submitted as a feature request, I didn't find it. My use case is similar to OP's. I want to use tags to attach tasks to projects, and group tasks using the project's title (or any other property in the project's master note) as group header, instead of the tag itself. I have a workaround that uses "app", but I agree with Clare that it would be best if the functionality is provided by Tasks. |
Beta Was this translation helpful? Give feedback.
-
|
I spent a lot of time on this already, and didn't come up with a solution I considered releasable. And I don't track conversations in Q&A, so no, definitely no plans to work on it. Reading back on this, I found it quite hard to understand what the request is, because it essentially seems to say "read a file in a .zip" to understand the request. I don't guarantee that if an FR is created, it will be worked on. But doing so would at least give it a non-zero chance of being remembered. But the FR would need to contain, as Markdown fenced code blocks not .zip, a real-world example of what is required. Part of the FR process is checking to see whether there are any existing requests. You can filter the existing FRs for the labels on this discussion, to narrow down the search. |
Beta Was this translation helpful? Give feedback.

tl;dr
No, it's not possible in a reasonable amount of time, using Tasks 7.21.0
Details
I've spent more than 45 minutes on this today - half an hour of which was after receiving the sample files, for which thanks again.
My conclusion is that the request functionality is not currently possible in Tasks, unless someone is already familiar with the Obsidian API.
What next?
You are welcome to create a Feature Request on the Tasks plugin, if you would like this to be considered for implementation in future.
If I were less unwell I might have been able to make some progress, but I really should focus on getting better.