Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
April 28, 2021 at 9:36 AM #44261
In reply to: Using Shortcuts on iOS
Daniel Leu
ParticipantOne way of using
tapformz://is calling a TapForm script from an external application. This is document in https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api under the paragraph “Calling a script from a URL”.Another use is to open a record. On the desktop,
Copy Record Linkin the Edit menu copies the URL needed to the clipboard. It has the form :tapformz://record/view/db-xxx/frm-xxx/rec-xxx.On mobile, when you show a record, click on the menu on the top right, select
Copy Record Link.Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksApril 23, 2021 at 1:09 AM #44235Sam Moffatt
ParticipantI think you should learn some JavaScript as well, you’ve already started the journey, it’d be a shame to end it here! You started off in your OP not confident you could do it though now you end it with a bona fide Tap Forms bug under your belt and your first successful script!
Humble Bundle are currently doing a sale on O’Reilly’s Head First series which includes their Head First JavaScript book along side a bunch of other books. Head First has a slightly different approach in their books and the bundle level to get the JavaScript book is $10. That book, like most Javascript resources, focuses on Javascript in web development but a lot of the language features and functionality apply to Javascript in Tap Forms as well. Also at the $10 tier is their Learn to Code book which uses Python as an introduction language and might also be helpful in learning how to code. Each programming language has their own quirks which is the fun part in writing code.
Thanks for the clearance, I’ve added it to my backlog to add to the channel.
April 21, 2021 at 11:23 PM #44234In reply to: Check on empty blob field
Daniel Leu
ParticipantI’m glad I added scripting then Daniel! :)
:)
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksApril 21, 2021 at 10:12 PM #44233In reply to: Check on empty blob field
Brendan
KeymasterI’m glad I added scripting then Daniel! :)
April 21, 2021 at 7:49 AM #44232In reply to: Check on empty blob field
Daniel Leu
ParticipantHi Dirk, welcome to scripting! Without scripting, I wouldn’t be a TapForms user!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksApril 21, 2021 at 5:23 AM #44231In reply to: Open a Finder window
raily74
ParticipantHello Brendan, hello Sam,
after a week in the test with folder alias and Script Folder Access, both ways come to problems. In both cases it seems to be a bug.
1. The way over the folder alias (Brendan)
In Tap Forms, I double-click on the alias to get to the Finder folder. In case of creating a new subfolder or changing the name of an existing one in finder, I then have two aliases in Tap Forms of which the lower only works. So I always have to delete an alias after such an action.
In case of creating a new subfolder without using the alias before, every works fine. But than I have to search for the folder manually.2. The way over the URL (SAM) – my preferred way
If the Script Folder Access is set once, it works fine as described last week. As soon as I restart Tap Forms, it doesn’t work anymore. I first have to define the Script Folder Access again in the preferences.Would be nice to get this working because it’s very important to me. There are a lot of files I don’t want to sync to iOS. So it would be nice to get to finder with one click (URL) ore with double-click (alias) and without errors.
Thanks a lot for your help.
April 21, 2021 at 4:42 AM #44229MiB
ParticipantThank you, I’ve changed that.
Of course you can use whatever you wish from this conversation. I have learned a lot, and it was fun. I think, I should learn some java script, just for fun. :-)
I will attach the latest files. You can use them in your video if you like.
– Or everybody else, who is reading here. You just have to change the username “mib” to your own in the Script and in the command file.Attachments:
You must be logged in to view attached files.April 20, 2021 at 11:08 PM #44227In reply to: Check on empty blob field
Dirk Soenen
ParticipantHi Daniel,
Thanks for your response. I’ve never used scripts, this is definitely the moment to explore. I’m starting with the tap forms javascript scripting 101 manual today. Never too old to learn.
April 20, 2021 at 5:41 PM #44226Sam Moffatt
ParticipantIndeed! Good news you got it sorted and you’ve begun your Tap Forms scripting journey!
April 20, 2021 at 5:36 PM #44225Sam Moffatt
ParticipantSounds good!
One other thing I noticed you created the script as field script, I think you should recreate it as a form script. Form scripts are intended to be run on demand which fits this case more. Script fields update when a referenced field changes and are more intended to work with the individual records.
Once Brenden’s done the public release, I’ll do a video with this. Do you mind if I use your use case and sample data as an example?
April 20, 2021 at 2:50 PM #44223In reply to: Grab name from iOS Contacts record?
Daniel Leu
ParticipantYour contact field returns just a regular javascript object. To get the name, you can use
contact.nameorcontact["name"].Example:
function Get_Contact_Name() { var contact_id = 'fld-xxx'; var contact = record.getFieldValue(contact_id); return contact["name"]; } Get_Contact_Name();Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksApril 20, 2021 at 2:28 PM #44222Topic: Grab name from iOS Contacts record?
in forum Script TalkFern
ParticipantIs there a way to grab only the name of the linked Contact? (I’d love to not have to manually enter a contact’s name; I’ve just been linking to a record in iOS’s Contacts.)
With my almost nonexistent knowledge of scripting, I’ve only gotten it to return the entirety of the iOS record, i.e.{ id = “blablabla”; name = “blablabla”; phoneNumbers = {home = blablabla; mobile = blablabla;};} etc
April 20, 2021 at 2:13 PM #44221Fern
ParticipantThis is my first time using scripts in TapForms and I figured out how to adapt Daniel’s version to my forms and where to put it! (Funnily enough I figured out the former first…) This is run-of-the-mill for people like you and Daniel, but it’s a total achievement for me. Thank you so much for your help!
April 20, 2021 at 9:54 AM #44220In reply to: Check on empty blob field
Daniel Leu
ParticipantYes, you can check this in a script:
function Has_Photo() { var photo_id = 'fld-xxx'; var photo = record.getFieldValue(photo_id); if (photo.length == 0){ return "has no photos"; } else { return "has " + photo.length + " photos"; } } Has_Photo();Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksApril 18, 2021 at 11:13 PM #44207Sam Moffatt
ParticipantThanks a lot for your effort!
I fiddled around with this (again: without knowing any java script, so excuse me for asking dumb questions).We learn by asking questions and making mistakes, if you’ve got the question there is also likely someone else like you that has a similar question. My hope as always is that this helps not only yourself but maybe someone else who finds this with similar questions.
ls * > files.txt results in a listing of all directories with an “:” after it an everything in it.
ls > files.txt results in just the directories, but also the files.txt which is created before the txt-file is filled.
ls -d */ > files.txt eliminates that issue but generates an “/” behind each directory.
The solution would be: ls -d */ | sed -e ‘s-/$–‘ > files.txtMakes sense, I did some playing and this might also work out for you:
find * -mindepth 0 -maxdepth 0 -type dIt’s a single command but I’m not sure we’re gaining much at this point. I was thinking about find earlier but it has it’s own quirks but this seems stable from my limited testing. My personal use case involved just JSON files so easy enough to wildcard match on those filenames.
The colon being appended seems weird though, I wonder if that’s some other sort of flag being introduced. I’ve not seen that before, very interesting. The colon used to be the old MacOS path separator so perhaps it’s that?
– This line crashes tapforms:
targetRecord.addPhotoFromUrlToField(prefix + sourceFile + “/folder.jpg”, foto_id);
That might be a bug for @Brendan to look into then, it’s probably not handling the
file://prefix properly.Three hours later reading through the basics of regex and Stackoverflow, I have fixed that:
let pieces = sourceFile.match(/(.*)\s\[([^\]]*)\]/);works fine.
Glad to hear you figured it out, as I said it’s close but obviously not something I was able to directly test and validate so I expected some minor tweaks.
What doesn’t work:
– One additional (empty) record is made. I guess from the “files.txt in the same directory. (Not really a problem. I just delete it.)This might be that there is an empty line from the
\nsplit, something simple that might catch that is the following:for (let sourceFile of indexFile.split("\n")) { if (sourceFile.length < 3) { console.log("Empty source file, skipping: " + sourceFile); continue; }Basically if the length of the string is less than three (empty string, “.” or “..”) then it’ll skip that line. Assumption is that your folders will always be three or more characters long.
– info.txt is nowhere to be seen in the records.
I’d do a
console.logon the return value of theUtils.getTextFromUrl(prefix + sourceFile + "/Info.txt")just to see what you’re getting back as a first step for debugging. I did some testing and it feels like maybe the spaces are being messed up by Tap Forms, perhaps another bug for Brendan.– folder.jpg does not appear anywhere in the records. The line of code crashes tapforms.
If it is changed to:
targetRecord.addPhotoFromUrlToField(foto_id, (prefix + sourceFile + “/folder.jpg”));
(foto_id in front of the path and brackets) it doesn’t crash, but isn’t doing anything either. _ And that’s not the order in which it should be, regarding to the manual!The swapped order likely doesn’t crash because it can’t find the field and is probably silently failing instead of outright failing. Crashing Tap Forms probably should have generated an alert for @Brendan though in those cases if you have a crash dump I usually also reach out to support@tapforms.com with the crash dump to let him know what I was doing if I can reliably reproduce it to get it fixed. As I said this isn’t something I’ve tested personally but is something at some point I want to work towards.
Not all jpgs are named “folder.jpg”. Would it be possible zu take just *.jpg and add it? (Of course I have to make sure, there is just one then.)
Once the above bug gets fixed then you can use a similar sort of index file technique to generate a well known file path to import the JPEG files from. This is a little ugly but is something like what I’d do to get it to work:
(IFS=$'\n'; rm files.txt; for FOLDER in $(find * -mindepth 0 -maxdepth 0 -type d ); do echo "$FOLDER" >> files.txt; pushd "$FOLDER"; pwd; ls *.jpg > images.txt; popd; done )It’s a bit ugly and intended to be used with bash. The
IFSportion tells bash to use newlines to split strings so that spaces don’t mess it up. I’m going to use this one liner to also generate thefiles.txtas well, so we delete it before the run starts. I used thefindsyntax from earlier to find all directories in the current directory and thefor FOLDERto loop over them. I dump the folder name into thefiles.txtfile and change into that directory withpushd. Thepwdis there to just print out the full path for debugging just in case you end up somewhere you’re not expecting. Thelsis there to grab the files and thenpopdto go back ot the parent directory. It’s wrapped in parentheses to prevent theIFSfrom persisting beyond the command execution. I’d probably put it in a simple shell script for safe keeping as well.Then in Tap Forms you can use
Utils.getTextFromUrlon that path and loop over it to add it to the photo field.Sounds like we’re making progress though! Now it feels like we’re hitting some bona fide TF bugs :D
-
AuthorSearch Results