I am newbie with Applescript and Automator. I am trying to build a Quick Actions which will be able to propose different functions according to the type of file for example.
If the file is test.sh quick action will be a and b
If the file is document.pdf action will be c and d
I succeed in creating my actions but not to make them specific to file type. I don't know where to start as I don't see any possibility to make input conditional like if input = .sh do a and b.
Any help on how to proceed will be really appreciated.
Thank you,
After looking at the image of your QuickAction, it is not at all useful for anything other then a selected PDF document in Finder.
The first action should be a Set Value of Variable action so its contents can be retrieved multiple times using Get Value of Variable with however many Filter Finder Items actions needed to process the different file types, followed by the appropriate actions for each file type.
You would also use Ignore this action's input checkbox under Options for this action to detach it from the previous set of actions.
The image below shows a rough outline example of what I'm referring to:
Quick Actions are meant to be type-specific, so in general the best practice is to write one Quick Action for each file type. These quick actions will only appear in the Finder when files of that type are selected.
In many cases you can specify the file type when you create or edit the Quick Action in Automator. For instance, to create a Quick Action that appears only when PDF files are selected, set the pulldown menus at the top of the workflow to say "Workflow receives current PDF files in Finder":
then complete and save the Quick Action.
If you want more fine-tuned control over what types of files the Quick Action 'sees', you can edit its info.plist file and change its file types. After you've saved the Quick Action, navigate to ~/Library/Services in the Finder (that's the Services folder in the Library folder of your Home folder). Find the package with the name of the Quick Action (e.g., "Open in Preview"), control-click on it to get the contextual menu, choose Show Package Contents, and then open the Contents folder. You'll see the following:
Open that info.plist file in a plain-text text editor — I prefer BBEdit, but TextEdit will work fine if you make sure 'rich text' is turned off — and look for the NSSendFileTypes key. It will look something like the following:
<key>NSSendFileTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
com.adobe.pdf is a Uniform Type Identifier (UTI), and you can add or substitute in any system-recognized UTI. Here is the list of system-declared UTIs, but applications can declare their own UTIs and register them with the system, so this list is not necessarily exhaustive. For instance, if you want your Quick Action to send both PDFs and image files to Preview, you would search on the system-declared UTIs page and find that the base UTI for images is public.image, and then edit the info.plist to read:
<key>NSSendFileTypes</key>
<array>
<string>com.adobe.pdf</string>
<string>public.image</string>
</array>
Save this, and the Quick Action will now appear whenever you selected PDFs or images. Note that if you manually edit the info.plist file it might get overwritten if you edit and save the Quick Action in Automator.
Only the first two relevant Quick Actions will appear in the Finder window; any extras will be collapsed under the more button. To change the ordering so that the Quick Actions you use most are up first, open System Preferences, click the Extensions item, open the Finder section, and drag the items in the right-hand list into the order you prefer.
Related
I've been trying to format my Evernote notes (thousands of them) so that they are readable on any device.
I've accessed evernote storage on my Mac and saw folders of entries -- every folder contains a note.xhtml and a content.enml files, which directly stores note contents.
I can modify the *.xhtml file, and changes are reflected on Evernote client, but they just won't sync over to the server. Additionally, the *.enml file contains corresponding content to xthml file, but the change won't go there.
Is there any way I can neatly edit my notes, on the HTML level?
Thx!
In AppleScript, it's pretty easy to get and set the HTML. To actually manipulate the HTML you might want another language.
Here's how you read and write HTML content to a single selected Evernote note:
tell application "Evernote"
set noteList to selection
set n to item 1 of noteList
set extractedHtml to HTML content of n
set HTML content of n to "<p>Foo Bar</p><p>foo baz</P>"
end tell
Evernote provides some good examples of using AppleScript on their developer site. You can also use xsltproc for some more systematic manipulation. I have a read-only example of using xslt via AppleScript in a recent post of mine. This above little snippet might be enough of an example to tell you how to set the HTML content.
But, to give you a better answer, I'd need to know a little more about how you want to manipulate your notes. The above example just grabs the first item in your current selection and sets the content.
In Xcode 5, can you sort the list of code snippets?
I've made one of my own and it's down at the bottom. I'd rather have it be up at the top.
One cannot automatically sort the snippets. One can go into the snippet file and reorder the snippets. System snippets are always presented first so to move a user snippet to the top one would copy the data for the snippet between the dictionary tags (....) to the top of the system snippets.
How to do it
Be advised that it is likely one would lose the ordered snippets when Xcode is upgraded so this should be considered but here is the way to force the issue:
Backup the affected system snippet file
(/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets)
for safety
User snippets are stored as a series of xml files located in the
following directory ~/Library/Developer/Xcode/UserData/CodeSnippets/
Create a user snippet
Go to the user snippets folder and open the file just created with a
text editor (these are just xml files so TextEdit, TextMate, et al
will do)
Copy the user snippet between the ... tags
Paste the user snippet data into the system snippet data at the top
Why you should avoid doing it
Changes will likely be lost when Xcode is updated
You can and should create a shortcut that will allow you to type the
entire snippet into code easily
Your title of the snippet is also searchable (making the snippets easy to find)
What is the alternative
I suggest you open an enhancement request at http://bugreport.apple.com to ask Apple to make a sort option available.
I have an application that can load in third party code. One of the capabilities that the third party code can do is add formats in which the app can export to. I am using saveDocumentTo: as means for implementing export.
I understand that I can customize the menu of available filetypes to save in via overriding writableTypesForSaveOperation: for my document, but what doesn't work is that in the save dialog an appropriate file extension isn't added to the filename when selected from the menu.
I tried overriding fileNameExtensionForType:saveOperation: but that doesn't even get called.
How can I make the Save dialog find the correct file extension (provided it isn't known at compile time)?
I've done this within a custom export accessory view for the Save Panel. The custom export accessory view just changes the NSSavePanel's allowed file types whenever the user changes the format they want to export to.
If you want to set the extension, pass an array with one element containing that extension.
The docs have some important detail for -[NSSavePanel setAllowedFileTypes:]'s behavior in this regard, for supporting more complex cases:
Discussion
A file type can be a common file extension, or a UTI. A nil value indicates that any file type can be used. The default value is nil.
If no extension is given by the user, the first item in the allowedFileTypes will be used as the extension for the save panel. If the user specifies a type not in the array, and allowsOtherFileTypes is YES, they will be presented with another dialog when prompted to save.
NSOpenPanel: In versions of Mac OS X less than v10.6, this property is ignored. For applications that link against v10.6 and higher, this property determines which files should be enabled in the open panel. Using the deprecated methods to show the open panel (the ones that take a types: parameter) will overwrite this value, and should not be used. The allowed file types can be changed while the panel is running (for example, from an accessory view). The file type can be a common file extension, or a UTI. This is also known as the “enabled file types.” A nil value indicates that all files should be enabled.
You may also see dedicated export dialogs in some cases which can reduce the complexity of this if you have several distinct formats. As before, you just update the allowed file types to support this (not necessarily dynamically in this case).
"Change an item in the navigation? Sure I can do that in 15 minutes."
So I am trying to update the navigation on a site that I inherited only to find out that the previous programmer was a college student and was using this site as a project of some sort. Needless to say there are zero comments and the code calls function after function and I just can't follow the logic.
I am looking for a roundabout way to update the navigation. I tried using Dreamweaver to search through all of the files in the site and look for any files that contain the name of the page or the url (hoping to find some sort of included file). There was none. I did file text files that control the main navigation but none for the subnavigation.
There is no database.
If it helps here is the site. http://bit.ly/jbs639
And if you want to look at the interesting text file that is parsed to create the main navigation you can find it here: http://bit.ly/m3erna
Hmmm.... Interesting indeed. You have my sympathy.
One thing that I would look at... The file that gets parsed for the main navigation appears to be a simple delimited file. Sure, the delimiter is a rather unusual +++, but that choice means it avoids conflict with things like commas that might be desirable in the link text. It looks as if the last element indicates what type of resource is being accessed (file or directory, although I don't know what - if any - effect that has on the final output). It also appears that there are similar text files (in the framework/cfg/nav/ folder... which should probably not be generally accessible BTW) for the sub-menus. (E.g. the file stores.txt appears to contain the additional navigation items associated with the stores sub-navigation).
You don't mention which sub-menu you're trying to change. I suspect it is the "About TTO" one, which I can't find an entry for... but I'd look to see if there are any similar navigation text files in the /content/about/ folder.
Good Luck!
Of course it was as simple as a function that reads all of the files in the directory and the name of the file. I guess that in this case there was no shortcut.
After tinkering and modifying a GUI I have been working on for some time I ended up with a group of EditControllers and Radio Buttons that I do not need any more, so I would like to get rid of them. However, if I simply delete them from the GUI edit, I get assertion errors. How am I supposed to get rid of these elements?
You need to remove all code from your program that refers to the deleted controls. For each control you want to delete, take its ID and search the source for statements that refer to it.
Start like this:
Check the ID of that given control. Copy it. Now remove the control from dialog resource.
Ensure that ID is not used by other dialogs. If not, you can use following.
Delete that ID from resource.h.
When you compile it, you'd get error (around GetDlgItem, DDX_Control etc). Remove or comment them. Remove appropriate CWnd-derived variables (like CEdit, CComboBox etc).
You are done!
If given ID is used by other dialogs (check it from Resource View's context menu Resource Symbols...), then you cannot directly remove it from resource editor. You, however, need to remove it from appropriate implementation file (of CDialog/CPropertyPage-derived class).