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: 6 comments 27 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.

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.