Why is FileMaker Pro giving me an "Object not found" error? - applescript

In a FileMaker Pro (v12) script I'm trying to use an Applescript to call a shell script to create an md5 hash of a passed in variable and set the result to a cell in my database. The variable $key_secret_utime is successfully being passed in and I'm am successfully getting a result from my shell script so all of that is just for context.
However, when I try to set the result to a cell in my database I get an "Object not found." error and "Unknown Error: -10006."
I'm pretty confused by the syntax of cells/fields database/document and what not so I'm sure I'm just making a simple error. What am I doing wrong?
Also, is there a better way to be doing all of this?
Here's my Perform Applescript script step:
"
set myData to \"" & $key_secret_utime & "\"¶
set cmd to \"echo \" & myData & \" | md5 -q\"¶
do shell script cmd¶
set cellName to \"rovi_md5_string\"¶
tell me¶
set data of cell cellName of current record to result¶
end tell
"

For one thing, make certain that your field rovi_md5_string is on the layout that you are on when you call the script.
Second, result is returning cellName, not the result of your shell script. Instead you can set a temporary variable to result below the do shell script line.
This worked for me when I had rovi_md5_string on a layout:
"
set myData to \"" & $key_secret_utime & "\"¶
set cmd to \"echo \" & myData & \" | md5 -q\"¶
do shell script cmd¶
set myResult to result¶
set cellName to \"rovi_md5_string\"¶
tell me¶
set data of cell cellName of current record to myResult¶
end tell
"
Take a look at my answer to this question for some thoughts on creating nice AppleScripts in FileMaker: How to pass data from a FileMaker field to an Applescript

Related

How to use output from one 'do shell script' for another one in Applescript

I'm using a Mail.app rule (MacOS Mojave) that creates a TaskWarrior task for the selected email message by using AppleScript that uses a 'do shell script' command.
Creating the task is no problem, but I want to annotate the task, which requires that you use the output from the shell script - which is "Created task [number]". Because annotating the task is the following shell script: task [number] annotate [your annotation, in my case a link to the email message].
I thought I managed to get the "Created task [number]" result from the first shell script to "task [number]" which is the beginning of the second shell script, but the Result is now that No command is specified - assuming 'information'.
I've tried to use delay 1, so that one shell script wait for the other to finish, but to no avail.
This is the specific script:
tell application "Mail"
set selectedMessages to selection
set theMessage to item 1 of selectedMessages
set messageid to message id of theMessage
-- Make URL (must use URL-encoded values for "<" and ">")
set urlText to "message://" & "%3c" & messageid & "%3e"
set onderwerp to subject of theMessage
set DueDate to display dialog "Wat is de due date?" default answer "friday"
do shell script "/usr/local/bin/task add Email over " & onderwerp & " beantwoorden due:" & (text returned of DueDate) & " project:Work +email"
-- This all works as it should. A task is created with the email subject and a due date that I give it. However, from here something goes wrong
set task to the result
set laatste to rich text 1 thru -2 of task
set annotate to rich text 9 thru -1 of laatste
do shell script "/usr/local/bin/" & annotate & " annotate" & urlText
end tell
I expected that the output would be that task [number] is annotated with urlText of the message. But I get:
error "Mail got an error: No command specified - assuming
'information'. No matches." number 1
No command specified - assuming 'information'.
Ask yourself why TaskWarrior cannot see that the command is “annotate”. It’s because your second command syntax is wrong. Change
& " annotate" &
To
& " annotate " &
Note the space.

How to intentionally corrupt a file with Applescript

What I'm trying to do is essentially shred a file. I was recently in a security protocol meeting at my company, and one of the speakers showed us how he could recover a file that was put in the trash folder and then emptied from the hard drive. Being a new guy on the IT team, they asked me if I could find a way to "shred" the file. Essentially what I want to do is this:
-drag/send a file to a folder/applet:
-have an AppleScript open the file in text edit:
-use a "randomly" generated ASCII string (see below) to encrypt/corrupt the text:
-save the file, and then delete it with the "remove" shell script:
-if at all possible, find a way to instantly rewrite the part of the drive that contained the file previously:
This is what I have so far. It's just pieced from previous projects I did and some looking online.
--this is the "random" generator
set passphrase to ""
repeat with x from 1 to 100
set randomChar to ASCII character (random number from 50 to 100)
set passphrase to passphrase & randomChar
end repeat
--end generator
tell application "Finder"
set sel to selection
if sel is not {} then
set als to sel's item 1 as alias
set aPath to POSIX path of als
set oldPath to aPath & ".old"
set oldPath2 to quoted form of oldPath
set aPath2 to quoted form of aPath
--display dialog "Enter a password for encryption" default answer "password"
set password1 to passphrase
set scRi to "openssl des3 -in " & oldPath2 & " -out " & aPath2 & " -k " & quoted form of password1
set RenameToOld to "mv " & aPath2 & " " & oldPath2
set DeleteOld to "srm " & oldPath2
--display dialog scRi
tell application "Terminal"
activate
do shell script (RenameToOld)
do shell script (scRi)
do shell script (DeleteOld)
end tell
end if
end tell
end open
sorry if the spacing is off. I keep getting an error saying that the variable "passphrase" is not defined, even though I tried to fix it plenty of times. It seems to corrupt any file it is handed, but I don't know why or how. If somebody could figure out how to get it to work, I would be very grateful.
The srm command is gone in 10.12, along with Finder's Secure Delete option. Apple sensibly eliminated them as they don't work on SSDs, nor do they destroy previously written or backup copies. As the new IT guy you really need to educate yourself before you take responsibility for anything security-related. See also: Security Theater.

Web search for filename using Automator

I'm attempting to formulate an Automator script that takes a filename from Finder and searches for it on a specific website using Google.
It looks like I'm getting the filename right and can put it in a variable, but I can't figure out if there is a way to pass the variable to the search URL. There is no variable input field for URLs. Can perhaps some intermediate function be used?
You can use this script, it return an URL (no need for other actions or variables):
on run {input, parameters}
set tName to name of (info for (item 1 of input) without size)
return "https://www.google.com/search?q=" & tName & "%20site%3Amywebpage.com"
end run

Using multiple rsync jobs in applescript

Hello I want to use AppleScript to copy a file from a source Macserver to 10 other Mac servers using rsync. I have the basics working:
set source to "/Folder1/Folder2/"
mount volume "afp://username:password#server1/Folder1/"
set Folder1 to result as alias
set destShareName to "/Volumes/Folder1/Folder3"
do shell script "/usr/bin/rsync -rlptD --log-file=/Users/user/Documents/rsync.txt " & (quoted form of source) & " " & (quoted form of destShareName)
It works and I get a log of the job. I know I could copy the job and substitute server1 with server2 and run the job again. How can I create a list of servers and get the rsync job to run recusively through the list? Many thanks, John
Something like this. You make lists and use a repeat loop. The first time through the repeat loop you grab all the first items in the lists, so make sure all the first items in each list go together. The second time through you will grab all the second items and so on. Note that all the lists should have exactly the same number of items.
set theServers to {"afp://username:password#server1/Folder1/", "afp://username:password#server2/Folder1/"}
set sourceFolders to {"/source1Folder/Folder2/", "/source2Folder/Folder2/"}
set destFolders to {"/dest1Folder/Folder2/", "/dest2Folder/Folder2/"}
repeat with i from 1 to count of sourceFolders
set thisServer to item i of theServers
set thisSource to item i of sourceFolders
set thisDest to item i of destFolders
mount volume thisServer
do shell script "/usr/bin/rsync -rlptD --log-file=/Users/user/Documents/rsync.txt " & (quoted form of thisSource) & " " & (quoted form of thisDest)
end repeat
EDIT: based on your comment, if only your server changes then you could adjust your code like this...
set theServers to {"afp://username:password#server1/Folder1/", "afp://username:password#server2/Folder1/"}
set sourceFolder to "/source1Folder/Folder2/"
set destFolder to "/dest1Folder/Folder2/"
repeat with i from 1 to count of theServers
mount volume (item i of theServers)
do shell script "/usr/bin/rsync -rlptD --log-file=/Users/user/Documents/rsync.txt " & (quoted form of sourceFolder) & " " & (quoted form of destFolder)
end repeat

Applescript - Getting a section of a POSIX path and creating a folder with that name

I have some files in a work folder that contains jobnames_jobnumber /work/jobnameA_001/outbox/filename.mp4, /work/jobnameB_002/outbox/flamename.mp4 e.t.c
I would like to have an applescript get the full POSIX path and extract just the jobnameA_001 part of the path then create a new folder with jobnames_jobnumber_date
Please note the jobnames are client names so they are not fixed length.
Please also note I am a complete newbie and am not sure what to research to find the answers. But i'll try.
Thank you kindly,
Here's code that does what you want:
# Extract all <jobName>_<jobNumber> tokens from matching paths.
set jobNamesWithNumbers to paragraphs of ¬
(do shell script "for p in /work/*/outbox/*.mp4; do echo \"$p\"; done |
awk -F/ '{ print $2 }'")
# Get the date in format YYYY-MM-DD, e.g., "2014-04-13".
set dateString to do shell script "date +'%Y-%m-%d'"
# Specify the target folder in which to create the new folders:
set targetFolder to POSIX path of (path to desktop)
# Build the absolute paths of the folders to create.
set quotedFolderPathList to ""
repeat with itm in jobNamesWithNumbers
set folderPath to (targetFolder & "/" & itm & "_" & dateString)
set quotedFolderPathList to quotedFolderPathList & " " & ¬
quoted form of folderPath
end repeat
# Finally, create the new folders.
do shell script "mkdir -p" & quotedFolderPathList
Note that this relies heavily on using shell (bash) commands invoked with do shell script, which makes for much shorter code.
This comes at the cost of having to understand two languages, however.
Given AppleScript's limitations, it's worth making this learning investment in the long run.

Resources