Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 1,336 through 1,350 (of 2,952 total)
  • Author
    Search Results
  • Sam Moffatt
    Participant

    You can do it with a bit of work, I have a similar sort of use case where I import copies of the YouTube videos to a document that also includes the autogenerated subtitles so that I can do some searches on them.

    It’s a bit of work to set up, basically you need a text file that lists all of your other files in it because Tap Forms can read files from disk via the Script Folder Access. Unfortunately I don’t know of a way to natively traverse directories but the work around is to use something like Utils.TextFromUrl() to get a candidate set of files.

    Here’s a copy of the script I use to import from disk:

    document.getFormNamed("Script Manager").runScriptNamed("getRecordFromFormWithKey");
    
    var thumbnail_id = 'fld-eb22e30a9e4c4d7f9997b7d3a66ffb3a';
    var title_id = 'fld-4e8e68e2979643be8417c3469015abff';
    var description_id = 'fld-429934cd6ae646b1ac1cf5ad659cb926';
    var url_id = 'fld-b46c858779094c9d906f2ce5e5c4a028';
    var upload_date_id = 'fld-fc1f8537415c4d6cabb8c0784b64f2a6';
    var thumbnail_url_id = 'fld-12b4e040711b4afea624c7c049fdd7ce';
    var subtitles_id = 'fld-05d11d1db96a420fbd66c9dd70bd3038';
    
    function Import_Entries() {
    
    	let prefix = "file:///Users/pasamio/Documents/YT Uploads/";
    	let indexFile = Utils.getTextFromUrl(prefix + "index.txt");
    	
    	if (!indexFile) {
    		console.log("No index file?");
    		return
    	}
    	
    	for (let sourceFile of indexFile.split("\n")) {
    		console.log(sourceFile);
    		let metadata = Utils.getJsonFromUrl(prefix + sourceFile);
    		console.log(JSON.stringify(metadata));
    		
    		if (!metadata) {
    			console.log("Invalid metadata file: " + sourceFile);
    			continue;
    		}
    		
    		let targetRecord = getRecordFromFormWithKey("Video List", url_id, metadata.url);
    		
    		if (!targetRecord) {
    			console.log("Failed to get target record!");
    			return;
    		}
    
    		// If the title is set, skip processing this record.
    		if (targetRecord.getFieldValue(title_id)) {
    			continue;
    		}
    		
    		targetRecord.setFieldValue(title_id, metadata.title);
    		targetRecord.setFieldValue(description_id, metadata.description);
    		targetRecord.setFieldValue(upload_date_id, metadata.uploadDate);
    		targetRecord.setFieldValue(thumbnail_url_id, metadata.previewImageURL);
    
    		let subtitlesFile = sourceFile.replace(/.json$/, '.srt');
    		targetRecord.setFieldValue(subtitles_id, Utils.getTextFromUrl(prefix + subtitlesFile));
    		targetRecord.addPhotoFromUrlToField(metadata.previewImageURL, thumbnail_id);
    	}
    	document.saveAllChanges();
    }
    
    Import_Entries();

    I have a tool that downloads the data from YouTube creating a JSON file and an SRT file with the subtitles. I then use the Terminal to create the index.txt file with this one liner:

    ls *.json > index.txt
    

    From here I can read all of the JSON files and parse them for data and then I load up the SRT file into a a notes field. At some point I plan on converting this into a video as well. Your use case is a little more complicated but I think it can be mostly done with the exception of the duration of the audio books. That might require some other tooling to do properly and maybe Tap Forms isn’t the greatest place to build that. I have some tooling that tracks my podcast times but that’s using MP3 and a little outside of Tap Forms’ native capabilities.

    Thanks for the kind words about the YouTube channel. I wanted to show some of the power of Tap Forms because it’s got a lot in it and hopefully being able to see step by step, with a few mistakes wrapped in, is useful for folks in a way written documentation doesn’t always provide. At some point I have a plan to put something like this up as a video as well.

    #44173
    Sam Moffatt
    Participant

    Scripts are stored in the database and if you use CouchDB you can sync them with an external editor. I have a script sync tool which creates a backup of the script fields and form scripts in a CouchDB sync’d document (I think you might be able to run it using nearby sync as well but configuring that is a pain).

    I never put it out to the public but there was a version of the Script Manager that was done entirely via PHP and CouchDB that would push updates to the scripts back into Tap Forms documents. If you combined something that updates named script files with a tool like fswatch to handle updates when you hit save then you’d likely have the experience you’re after.

    #44171
    cf
    Participant

    I think Daniel’s suggestion to disable syntax highlighting for sufficiently large files is a good short term workaround. Having a way to edit the script directly with an external editor would be another option (assuming it’s saved as a file rather than a database record), being able to have a “show in finder” or “open in”, for example.

    cf
    Participant

    Hi Sam, I do have field scripts and when I get into a state where I am able to reproduce I did try to comment out all the code in the scripts to rule that out, crash still occurred. I agree this has the markings of a race condition though unlike a typical race condition once im able to get into a state where it’s reproducible its consistently reproducible with those records.

    Anyway I don’t want this crash to distract from the original issue I posted, which I think is much more serious and very eager to see a fix for.

    MiB
    Participant

    I have posted this 5 minutes ago, but it was marked as spam and is gone… Sorry if it pos up twice later.

    Im am subscribed to Sams youtube channel on which he is explaining things within tapforms, I wouldn’t have thought of before. (If you don’t know the channel, check it out, it is called pasamio.)
    Watching this channel, tought me, that much more things are possible. So I wonder, if it is possible to automate the things I am doing over and over again.
    If so, I would be happy to pay someone, helping me with that project, because I can’t code in Java Script (or any other language than a bit html and css).

    The task:
    Filling tapforms with audiobook metadata.

    The status quo:
    A simple database with one picture and some other fields. No links or anything fancy.
    Files on a Mac. In a directory called “x” All in this format:
    Directory named: “title [author]” or just “title”
    in there:
    one or more or rarely none “.m4b” files
    one or none “info.txt” file
    one or more “.jpg” file

    What goes where in tapforms:
    The part of the directory name “title” goes to a text field.
    The part of the directory name “author” goes to a text field.
    The length of all combined m4b files goes to a time field with hours / minutes
    The content of “info.txt” goes to a notes field
    The “.jpg” file goes to a photo field

    What is “automated” now:
    I do a copy and paste of the content of the whole directory “x” in a text file. Then I replace all ” [” with a “;” and all “]” with nothing.
    Then I import the text file into tapforms, so the “title” and “author” fields are filled.

    What would be the goal:
    Getting all mentioned above automatically into tapforms.
    – title: always there, so it should be inserted into the field in tapforms
    – author: could be empty. So not even the brackets are there. Not “title []”, but “title”. If so, the field in tapforms should be empty too
    – jpg: If one jpg is in the directory, it should be in the field. If more are in the directory, non should go to tapforms (I have to choose by hand)
    – length: the length of all m4b files should be added and put into the corresponding field. If no m4b file is in the directory, the field should be empty
    – info.txt: The content of this file should go into the notes field. If there is no info.txt, it should be empty.

    Importing title and author by hand is no problem at all. Getting the time in the field is the most work. Then info.txt and lastly the jpg.
    If these three things could be automated -or all five – it would be fantastic.

    Is it possible with not so much effort?

    Attachments:
    You must be logged in to view attached files.
    #44154

    In reply to: Open a Finder window

    raily74
    Participant

    Hi Brendan,
    Thank you for your quick response. Up until now I have always used the Attachment field and the Alias function. However, if there is only one folder in it, the field will take up too much space on the form for its usefulness. The little link is much smarter there.

    Hi Sam,
    you are my hero today! Thanks for pointing out the “script folder access”. A function that I did not know before. It also took quite a bit of Google research to understand what you mean by that. But in the end I solved it and I’m very happy with it. Many Thanks!

    Michael

    #44149
    Sam Moffatt
    Participant

    Cool that you used the Script Manager though that script is 440KB in size compressed. I can understand why the syntax highlighter died on it. When I unminified it, it came to 35402 lines and 1.4MB. It’s a chunky bit of Javascript.

    #44148

    In reply to: Open a Finder window

    Sam Moffatt
    Participant

    Try using the script folder access to give Tap Forms access to a location on your hard drive and then you should be able to point to it.

    Sam Moffatt
    Participant

    Do you have fields scripts that work on the record? There might be a data race with the layout renderer and something mutating the record state?

    cf
    Participant

    Here’s an example of a script that will cause this:

    https://raw.githubusercontent.com/cfilipov/tfscripts/master/cheerio.js

    You can try copy-pasting the contents of that script directly in the TapForms script editor and it will beach ball forever. It’s possible if I waited long enough whatever was blocking the main thread would finish but after waiting a long time I just killed tap forms (which of course does not save the script). If I had to guess it’s the syntax parsing of the js causing the hang.

    As a workaround I used Sam’s script manager to download the script and add it without using the editor UI. This works for getting the script in tap forms and it’s runnable, however, if you try to open the script to edit/view it will also hang just like before.

    #44139
    Sam Moffatt
    Participant

    You can hide the script field and it’ll keep working when ever it’s dependent fields are updated. Something simple to take out the +44 assuming it’s at the start of the field:

    record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/^\+44/, '').replace(/[^0-9]/g, '');
    

    The ^\+44 basically says match the start of the string (the ^ character), match a plus sign (the \+ piece, + has special meaning normally so needs to be escaped) and then match “44”. If the +44 isn’t at the start then remove the ^ character (e.g. /\+44/) to just replace that string.

    I chain this as two replace statements just because it makes things a little clearer what is going on (e.g. you’re getting the field value, then you’re replacing the country code and then you’re making everything a number).

    Regex 101 link: https://regex101.com/r/hPF4kb/1

    Regular expressions can be a bit of a challenge to learn but if you’re doing string manipulation they’re an invaluable tool in many languages, including Javascript!

    #44138
    Andrew Drapper
    Participant

    Thank you so much.

    Works like a dream. I could fight on trying to parse the off +44 that some records have, but I think I will just hand modify as they come up.

    Presumably, I now hide the script field and let it do its stuff in the background?

    Andrew

    #44132
    Andrew Drapper
    Participant

    Sorry,

    I probably need to do a bit more reading into the manual but I now have

    function SMS() {
    
    	var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, '');
    	 	
    	var SMS = mobilephone + "@textmagic.com";
    	//console.log(SMS);
    	
    	return SMS;
    
    	const email_id = 'fld-d52d76de4eed468f9119a49b50a47f0d';
    	record.setFieldValue(email_id, SMS());
    	document.saveAllChanges();
    	
    
    }
    
    SMS();

    But though I do get a nice “07***726@textmagic.com” in my SMS Script field, it does not place anything in the email field.

    #44128
    Andrew Drapper
    Participant

    With some fiddling, I got this to work

    function SMS() {
    
    	var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, ''); 	
    	var SMS = mobilephone + "@textmagic.com";
    	console.log(SMS);
    	
    	return SMS;
    
    }
    
    SMS();

    But I now have this number in a script field and therefore can not click on the send email symbol.

    Can I now past this value into an email field?

    #44122

    In reply to: Scripts and searching

    Sam Moffatt
    Participant

    When you’re using a JOIN field, both sides are M:M relationships because it doesn’t know if it is singular or not. The calculation field there can’t handle the M:M relationship properly in the same way it it can being on the child side of the 1:M where there is only one entry. The solution for that is generally a script that just pulls out the first entry from the field.

    I use this construct to gather all of the child entries and join them together:

    var client_contact_details = record.getFieldValue('fld-beaf858dba7d4014b89722411ebcbd3f');
    if (client_contact_details) {
    	client_contact_details.map(r => r.getFieldValue('fld-0d5ab10b7374418bac721d6446c81b73')).join(' ');
    }

    First line gets the child records from the link to form, second line checks if we got a value back (avoid undefined error, mostly harmless but some defensiveness doesn’t hurt), the third line is a little bit to unpack though. The map function is like a short hand of a for loop to run a single function. In this case we’re going through each of the records in client_contact_details and “mapping” that value (a Tap Forms record) to the value of the field fld-0d5ab10b7374418bac721d6446c81b73. The last part of that line basically says to convert the array to be “joined” by spaces.

    For the JOIN count for documents, I did COUNT( Notarised documents - Join::Type of document ) and that seemed to work properly for me giving me a count of two.

Viewing 15 results - 1,336 through 1,350 (of 2,952 total)