With a great deal of help from #Chuck I have written this filemaker script which is supposed to find related PDF attachments in container fields and export them to a temporary folder then trigger an applescript which will open & print the documents using adobe acrobat.
Unfortunately the script will not work and although I have used script debugger and tried to follow advice I am still having difficulty. Any assistance in telling me exactly where I'm going wrong would be appreciated.
Go to Related Record [Show only related records; From table: “Attachments”; Using layout: “Attachements Report" (Attachments); New window]
Enter Find Mode []
Constrain Found Set [Restore]
Sort Records [Restore; No dialog]
#
#After finding the related attachments and constraining them to the specific type we rename and export them to the desktop
#
Go to Record/Request/Page [First]
Loop
Set Variable [SPath; Value:"fi|emac:" & Get ( TemporaryPath ) & Attachments::Record number &"-' & Attachment Type List 2::Prefix_z & Lien::Lien_lD_z]
Set Variable [SASPath; Valuei"/' & Substitute( SPath; "filemac:" & Cet( SystemDrive )1 )]
Set Field [Attachments::g_app|escript_parameter; $ASPath]
Export Field Contents [Attachments::file_c; “SPath"]
Perform AppleScript ['set _pdf_path to contents of cell "g_applescript_parameter" of current layout batchprint(_pdf_path) on batchprint(mycurrentfile) tell application ‘Adobe Acrobat Pro" activate —- bring up acrobat open alias mycurrentfile “'_*]
Go to Record/Request/Page [Next; Exit after last]
End Loop
Close Window [Current Window]
Using Script Debugger I get the following errors...
On Script Step, Export Field - Error: “ "(VARIABLE FILE NAME).. could not be created on this disk. use a different name make more room on the disk.
On Perform AppleScript Step: Error: Object not found & Error: Unknown Error: -1728
Is this being executed on the server (via a schedule) or on the client computer?
Have you verified that the directory permissions are actually set correctly in the temporary path?
Have you tried using Get ( DocumentsPath ) instead of the temporary path, just to verify?
Related
I've just started out with AppleScript and I am trying to make a "new text file" thing in Automator. I keep getting this error: "Finder got an error: Can’t make class file."
Here is my code:
tell application "Finder"
set filename to display dialog "Enter Filename" default answer "newfile"
make new file at (target of front window) with properties {name:text returned of filename, file type:text}
end tell```
A get statement is usually optional, but in this case it is needed in order to evaluate the location specifier, since the statement is in the middle of the make command - see the AppleScript Language Guide. For example:
make new file at (get target of front window) …
You can also evaluate the location specifier using a separate statement:
set destination to target of front window
make new file at destination …
For example, I am trying using BetterZip for extracting files in applescript automation
The dictionary shows the syntax of the unarchive command:
COMMAND SYNTAX
unarchive file or list of file ¬
with preset text ¬
with options unarchive options
where the unarchive options is a predefined record type with a set of properties:
unarchive options (record)
PROPERTIES
Property Access Type
---------------------------------
clean archive get/set boolean
create extra folder get/set create extra folder (enum)
destination get/set file or destination folder
password get/set text
trash archive get/set boolean
In my code I want to use extract files with BetterZip
tell application "BetterZip"
unarchive "/path/to/zipfile" with options {clean archive:false, destination:original, create extra folder:never, trash archive:false}
end tell
In Script Debugger 6, the error is unable to coerce the data to the desired type {errAECoerionFail:-1700}
The status bar shows Stopped {Error: Can't make {clean archive:false, destination:original, create extra folder:never, trash archive:false} type unarchive options
So how to pass a record of a unarchive options type to the command?
Update:
I have found out the root of the problem, but I still can not figure out the solution.
The unarchive options can be retrieved via BetterZip's command get extraction preset with name "preset name", the return value is a record for example one in Script Debugger showing in AEPrint format as { 'uoDs':'Orig', 'uoEF':'efNv' }.
If I create a record with same keys and values, the AEPrint is { 'aoDs':'Orig', 'uoEF':'efNv' }, noticing the internal token for destination is different. (one is uoDs, the other is aoDs).
Further more, if I combine the records: {destination:original} & (get extraction preset with name "ExtractHere"), the return value appears to have duplicate keys rather than merging them: {destination:original, destination:original, create extra folder:never} and the AEPrint is { 'aoDs':'Orig', 'uoDs':'Orig', 'uoEF':'efNv' }.
So I think this is the reason why the unarchive command won't accept an unarchive options-like parameter because of the mismatched underneath key name.
But how to create one that matches the correct type?
When I want to unzip a file in AppleScript, I just use "do shell script" with the "unzip" command eg.
do shell script "/usr/bin/unzip \"/path/to/zipfile\" -d \"/path/to/output/location\""
I'm working on a simple AppleScript to make a copy of an iMovie project file. I have added this property to the script:
property iMovieProjects : alias (home directory of (system info) as string) & "Movies:iMovie Projects"
This gives me the error
File alias Macintosh HD:Users:my user name:Movies:iMovie Projects of wasn't found
What's the correct path? I tried iMovie Project.localized but that doesn't work either.
Try this, looks like you need to use the Finder. Also i added a little simplification on getting the home path.
property iMovieProjects : ""
tell application "Finder" to set iMovieProjects to alias ((home as string) & "Movies:iMovie Projects")
EDIT: Heres a one line solution that does not use the Finder, based on ideas from mklement0 & regulus6633
property iMovieProjects : alias ((path to movies folder as text) & "iMovie Projects.localized")
It appears this folder is some kind of special bundle type folder and thats why we were needing the finder to parse it correctly. Using its full .localized name resolves it.
UPDATE: As adamh discovered, the reason for the alias error is because the real name of the folder is "iMovie Projects.localized". Get info on the folder and you will see it.
I would add that an easier method to get to a folder is using the "path to" command. Using that you can get to virtually every known folder. In your case we can get directly to the Movies folder. You can look in the applescript dictionary of the standard additions to see all of the folders it knows. As such I would reference that folder as follows.
set iMovieProjects to alias ((path to movies folder as text) & "iMovie Projects.localized:")
Finally you'll notice that I did not use a property for iMovieProjects. That's because when you compile a script a property will hard-code the path into the script... meaning that the script will only work for this particular user. If the script is used by another user it will still point to the Movies folder of the person at compile time. Thus we don't use a property and the script will work for any user.
Good luck.
Update2 (thanks, #adamh): Even though the iMovie projects folder name appears as "iMovie Projects" in Finder in English-language locales, the actual - locale-independent - name is "iMovie Projects.localized". (If you want to refer to the folder by its localized name, prefix the set command with tell application "Finder", as in #adamh's answer's first snippet.)
You simply need to change how you parenthesize - the string to pass to alias must be built in its entirety inside parentheses:
property iMovieProjects : ""
set iMovieProjects to alias ( ¬
(home directory of (system info) as string) & "Movies:iMovie Projects.localized" ¬
)
Update1: #regulus6633 makes the excellent point that you shouldn't initialize a property with a specific user's path, as it will get compiled into the script. Thus, the above snippet initializes the property to an empty string and then assigns a value dynamically - which will then reflect the current user's path - in a separate set ... to statement.
Your original statement inadvertently creates a list with 2 elements, whose first element is a an alias of your home directory and whose second element is the string "Movies:iMovie Projects".
Simplified version with the path to command demonstrated in #regulus6633's answer (the same need to parenthesize applies):
property iMovieProjects : ""
set iMovieProjects to alias ( ¬
(path to movies folder as text) & "iMovie Projects.localized" ¬
)
I have attempted to follow the instructions on this post but I am falling short of understanding how some of the posters instructions work.
I want to be able to package the app with a prewritten bash script and then execute it, but don't follow from Step 4 onwards.
Post writes:
4. Also in your AppleScriptObjC script, add the following where appropriate:
property pathToResources : "NSString" -- works if added before script command
5. Where appropriate, also add the following in your AppleScriptObjC script:
set yourScript to pathToResources & "/yourScriptFile.sh"
-- gives the complete unix path
-- if needed, you can convert this to the Apple style path:
set yourScriptPath to (((yourScript as text) as POSIX file) as alias)`
6. As an aside, you could then open the file for read using
tell application "Finder"
open yourScriptPath
end tell
Questions:
Where do I add the line:
property pathToResources : "NSString"
Do I add which of the following, and where?
set yourScript to pathToResources & "/yourScriptFile.sh"
OR
set yourScriptPath to (((yourScript as text) as POSIX file) as alias)
How is it possible to execute the script itself? The mention As an aside, you could then open the file for read using only covers the Apple style path, it does not cover using the aforementioned style.
Can anyone shed a bit more light on this for me, or post a static copy of a AppDelegate.applescript file that shows how the original poster required the base code to be used? I have tried his method and looked across the internet for the past 3 weeks to no avail. I don't want to have to convert all my code for specific tools from bash scripts into AppleScript, as this would take a lot of work.
I only need to know how to reference to the script file (for example myBashScript.sh) in my app, which would reside in the application and be included by Xcode at time of compilation.
I think you should use the command path to resource <specifiedResource>.
See Standard Additions, path to resource.
You could set it by set myVariableName to path to resource "myBashScript.sh" or just use the command instead of your property so it points always to the right place (a user could move your app while running... lol).
ADDITION:
I did it that way in my AppleScript-Application:
on run_scriptfile(this_scriptfile)
try
set the script_file to path to resource this_scriptfile
return (run script script_file)
end try
return false
end run_scriptfile
Whenever I want to run a script that is bundled within my app I do this:
if my run_scriptfile("TestScript.scpt") is false then error number -128
run_scriptfile(this_scriptfile) returns true when everything worked.
I ended up bringing all the information together and now have a solution.
This takes into consideration the following facts:
firstScript = variable name that points to a script called scriptNumberOne.sh
scriptNumberOne.sh = the script that I have embedded into my application to run
ButtonHandlerRunScript_ = the name of the Received Action in Xcode
pathToResources = variable that points to the internal Resources folder of my application, regardless of it's current location
Using this information, below is a copy of a vanilla AppDelegate.applescript in my AppleScriptObjC Xcode project:
script AppDelegate
property parent : class "NSObject"
property pathToResources : "NSString"
on applicationWillFinishLaunching_(aNotification)
set pathToResources to (current application's class "NSBundle"'s mainBundle()'s resourcePath()) as string
end applicationWillFinishLaunching_
on ButtonHandlerRunScript_(sender)
set firstScript to pathToResources & "/scriptNumberOne.sh"
do shell script firstScript
end ButtonHandlerRunScript_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
Is it possible to save some kind of settings for an app create in AppleScript?
The settings should be loaded at the beginning of the script and be saved at the end of the script.
Example:
if loadSetting("timesRun") then
set timesRun to loadSetting("timesRun")
else
set timesRun to 0
end if
set timesRun to timesRun + 1
display dialog timesRun
saveSetting("timesRun", timesRun)
Where the dialog would show 1 the first time running the script, 2 the second time...
And the functions loadSetting and saveSetting would be the functions i need.
Script properties are persistent, though the saved value is overwritten by the value specified in the script whenever you re-save the script. Run:
property |count| : 0
display alert "Count is " & |count|
set |count| to |count| + 1
a few times, re-save it then run it a few more.
If you want to use the user defaults system, you can use do shell script "defaults ..." commands or (if using Applescript Studio) default entry "propertyName" of user defaults. In Applescript Studio, you bind values to user defaults.
This is also working well (check the first comment to the hint):
http://hints.macworld.com/article.php?story=20050402194557539
It uses the "defaults" system and you get your preferences in the ~/Library/Preferences
Applescript supports natively reading and writing plists through System Events:
use application "System Events" # Avoids tell blocks, note: 10.9 only
property _myPlist : "~/Library/Preferences/com.plistname.plist
set plistItemValue to get value of property list item "plistItem" of contents of property list file _myPlist
set plistItemValue to plistItemValue + 1
set value of property list item "plistItem" of contents of property list file _myPlist to plistItemValue
The only problem with this is that it can't create the plists so if the existence of the plist is not certain you need to wrap it on a try.
try
set plistItemValue to get value of property list item "plistItem" of contents of property list file _myPlist
on error -1728 # file not found error
do shell script "defaults write com.plistname.plist plistItem 0"
set plistItemValue to get value of property list item "plistItem" of contents of property list file _myPlist
end try