I'm trying to get/set value from Summary Service application using this code
tell application "SummaryService"
activate
delay 0.1
get value of text area 1 of scroll area 1 of window "Summary"
end tell
And whatever I do (get or set) I get this error
Error image
(!) Generally, I'd like to find a way of launching Summary App with text as an argument (I want to add this possibility into my obj-c app). I've googled for some time and what I get is this one. Nevertheless it makes all the work behind scenes, giving to user only result of text transformation and makes to do some amount of unnecessary work, while I just want to launch default app.
Any help will be appreciated!
System Events can get windows, scroll areas and text areas, SummaryService can't.
tell application "SummaryService" to activate
delay 0.1
tell application "System Events"
tell application process "SummaryService"
get value of text area 1 of scroll area 1 of window "Summary"
end tell
end tell
Finally I don't solve my question in the way I previously want, but I found that there're many opensource summerize libs on github, so I use one
Just one moment since I want to use code written in Swift in my Objective-C project is to add
#import <Reductio/Reductio-Swift.h>
To controller where I want to implement desired functionality and call
[Reductio summarizeWithText:textToChange compression:compressionValue completion:^(NSArray<NSString *> * _Nonnull result) {}];
To get result.
PS: I still interested how to open SummaryService programmatically with text I choose.
PS 2: Suddenly I found such function as NSPerformService, which do exactly what I want. So I implement all the needed functionality in this way:
NSString *stringToSetInPb = #"sample text";
NSPasteboard *pb = [NSPasteboard pasteboardWithUniqueName];
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pb setString:stringToSetInPb forType:NSStringPboardType];
NSPerformService(#"Summarize", pb);
So question officially can be solved!
Related
Is there any way to convert the following applescript to Objective-C/C?
tell application "System Events" to set visible of process "Safari" to false
I know I could execute this applescript in Objective-C using the NSAppleScript class or calling system("osascript -e '...'"), however isn't there another way?
How does applescript do this?
Alternatively can I hide a window from another application from Objective-C/C?
Update:
I have found out that you can use SBApplication class to do this:
SBApplication *SystemEvents = [SBApplication applicationWithBundleIdentifier:#"com.apple.systemevents"];
/*SystemEventsApplicationProcess*/ id Safari = [[SystemEvents performSelector:#selector(applicationProcesses)] objectWithName:#"Safari"];
[Safari setVisible:NO]; // Doesn't work!
However this doesn't work as setVisible probably doesn't do what I think.
This is the class hierarchy of SystemEventsApplicationProcess:
SystemEventsApplicationProcess : SystemEventsProcess : SystemEventsUIElement : SystemEventsItem : SBObject : NSObject
And here are the methods available for these SystemEventsXXX classes:
SystemEventsApplicationProcess
applicationFile
SystemEventsProcess
setVisible:
visible
unixId
totalPartitionSize
shortName
partitionSpaceUsed
name
id
hasScriptingTerminology
setFrontmost:
frontmost
fileType
file
displayedName
creatorType
Classic
bundleIdentifier
backgroundOnly
architecture
acceptsRemoteEvents
acceptsHighLevelEvents
windows
menuBars
SystemEventsUIElement
select
clickAt:
setValue:
value
title
subrole
setSize:
size
setSelected:
selected
roleDescription
role
setPosition:
position
orientation
name
minimumValue
maximumValue
help
setFocused:
focused
entireContents
enabled
objectDescription
objectClass
accessibilityDescription
windows
valueIndicators
UIElements
toolBars
textFields
textAreas
tables
tabGroups
staticTexts
splitterGroups
splitters
sliders
sheets
scrollBars
scrollAreas
rows
relevanceIndicators
radioGroups
radioButtons
progressIndicators
popUpButtons
popOvers
outlines
menuItems
menuButtons
menuBarItems
menuBars
menus
lists
incrementors
images
growAreas
groups
drawers
comboBoxes
columns
colorWells
checkboxes
buttons
busyIndicators
browsers
attributes
actions
SystemEventsItem
setName:
name
id
removeActionFromUsingActionName:usingActionNumber:
pick
keyUp
keyDown
increment
editActionOfUsingActionName:usingActionNumber:
doScript
doFolderActionFolderActionCode:withItemList:withWindowSize:
decrement
confirm
cancel
attachedScripts
attachActionToUsing:
stop
start
saveAs:in:
moveTo:
exists
duplicateTo:withProperties:
delete
closeSaving:savingIn:
setProperties:
properties
objectClass
SBObject
// ...
NSObject
// ...
You can use NSRunningApplication, which represents (as its name implies) a running application, and has a -hide method.
NSWorkspace will give you a list of all the running apps: [[NSWorkspace sharedWorkspace] runningApplications], which you can filter, or you can get the object representing Safari using its bundle identifier: +[NSRunningApplication runningApplicationsWithBundleIdentifier:] (note that actually returns an array in case there are multiple running instances of the same app).
The code won't work unless you add the scripting bridge framework to your project and a couple other things. Have you done that... I can't tell. This link seems to have a good explanation of what is required if you need instructions.
By the way, "set visible" means hide the application just like if you hid it from the application menu. However if you want to hide an application I'm sure there's an NSWorkspace method.
Last bit of advice... for only a few lines of applescript code NSApplescript would be your best option. If you intend to use lots of applescript script code then the scripting bridge is the better choice, although I myself often just put a compiled script in my project and then use NSApplescript to initiate the handlers from that script. You can also use the ApplescriptObjC language too. You have lots of choices.
I'm developing an iPad app that includes the ability to print a document. Some documents require rights management wherein a limited number of copies may be printed and the number of copies printed must be recorded.
I've scoured the UIPrintInteractionController documentation and have found no such capabilities. This question was asked here over a year ago: iOS Printing UI - limit number of copies and at the time this feature was not available - here's hoping it has since changed.
My questions are:
A year later, does cocoa touch still not have the ability to limit number of copies that can be printed?
Is there any way to GET the number of copies printed?
Is one forced to use the UIPrintInteractionController? If I'm unable to set or get copies, then I may be forced to write my own (if at all possible).
Trying to control the number of copies a user can print using UIPrintInteractionController.
I have the same problem and I was walking home and it hit me. Why dont I just create a category for the UIStepper and override its behavior.
I dont use the UIStepper in my app so this wont effect my app, but if you do theres probably a way you can selectively apply this code.
Anyway, you want something like this:
#implementation UIStepper (MJStepper)
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.minimumValue = 1;
self.maximumValue = 1;
}
return self;
}
#end
So create a category and include it in the same view which uses the UIPrintInteractionController
Then set the min and max values on init, and BAM. The print modal says 1 copy and has no uistepper. :)
You could set this to any number programmatically or even give the user a fixed range.
I really wish Apple had a full programmatic API for printing.
I am building a Kiosk app and the last thing I want is for the user to be able to print 100 copies of something.
I think the paper type and printer selection is still annoying but I can probably live with that.
Does anyone know if theres a way to control what Paper types your printer supports?
I know theres a delegate callback which I might be able to use to force a specific type of paper so I might try that.
Anyway, hope this helps! :)
in a method that is accessed three times I want to write something to the log.
NSLog(#"%#", [response responseString]);
But there is nothing in the log. The log windows is completely white. Normally when I start an application there is always some stuff that shows up in the log but now it is totally empty.
How can I fix this?
Perhaps a really silly thing, but in the top right-corner of the console you should see this:
Check that the middle segment or right segment is selected.
NSString *responseString = [response responseString];
NSLog(#"%#", responseString);
set a breakpoint on the first line and debug the application to see if its coming in this code in the first place. If it is, hover over responseString and it will tell you whether it is nil or not.
When Console isn't behaving nicely for me (which happens sometimes when I'm doing driver level stuff or multi-threaded apps), a much more reliable thing to do is something like:
- (void) printToLog: (NSString *) aFormattedStringToPrint
{
// don't forget to remove an older copy of this file before
// your app finishes launching
FILE * aFile = fopen( "/tmp/debuggingoutput.txt", "a");
if(aFile)
{
fprintf(aFile, "%s", [aFormattedStringToPrint UTF8String];
fflush(aFile);
fclose(aFile);
}
}
(you can define a macro like LOGTHIS which might toggle between NSLog and the above more direct and to the point code)
And then you can "tail -f /tmp/debuggingoutput.txt" in your Terminal window while debugging and if nothing appears there, then you know your debugging lines aren't getting hit.
Today I have been frustrated with a similar problem. When the console is activated, only the variables pane is showing. No sign of the console pane. After finding Debug Area Help via right clicking in the variable pane, i could see that it is meant to sit next to it on the right.
The key for me was to Hide the Utilities panel. For me, the little buttons shown in Luke's answer above would not appear until hiding and unhiding the Utilites panel.
Sorry to bug twice so quickly, but since people were so kind in their informative responces, I figured it couldnt hurt to ask another question.
The same program i tried to make it rather swanky and have a main screen which allows you to click on a button which leads to a limited options screen. This lets you switch the music on or off. Or at least it should do.
The music running code is in the main file (game.m), under the following:
//Music
[Settings setMusicEnabled:YES];
music = [SPSound soundWithContentsOfFile:#"music.caf"];
channel = [[music createChannel] retain];
channel.loop = YES;
channel.volume = 0.25;
if([Settings musicEnabled]){
[channel play];
}
I apologize for the strange format, but it is Sparrow framework. basically, the Settings file contains the class methods I am trying to use. If the methods cause YES, the music is on. If it is No, then the music is off.
settings.m
static BOOL isMusicEnabled;
#implementation Settings
+ (BOOL)musicEnabled
{
return isMusicEnabled;
}
+ (void)setMusicEnabled:(BOOL)value
{
isMusicEnabled = value;
NSLog(#"SME? %i", isMusicEnabled);
}
#end
Now, the options file is working and i tested that section. The program is reading that isMusicEnabled is getting a new value, thus musicEnabled is being altered as well, so there should be a change and the music should be switched off.
However, nothing happens. I have tried to use debugger, but I am not very good at it and I dont understand a lot of the information i am given. I do understand that the problem is sending the message from Settings file to the main/Game file.
I would appriciate anyone's help who could enlighten me as to how this could be solved.
I'm not familiar with Sparrow Framework, but let me make a guess anyway.
[channel play]; starts playing the music in background until the channel is asked to stop playing.
Changing the isMusicEnabled does not trigger any code to stop the currently playing music. When you change the value in Settings, you should inform the channel to stop (most probably by somehow accessing the channel and calling [channel stop].
There's another problem - isMusicEnabled is just a variable in memory, your program will not remember its state between restarts. And Settings are usually supposed to be remembered.
To summarize I see two problems: persisting settings between restarts first and informing about change of settings second. To remember settings I suggest you look into NSUserDefaults class. To inform the channel to stop playing you have couple of options - depending on you skills. Easiest is to simply access the channel variable from within the setMusicEnabled and call stop. Another option would be to use notifications, but for a beginner programmer that is more complicated (look for NSNotificationCenter if interested).
I'm trying to print a PDFDocument that I am constructing from a series of images. In case it matters, I'm doing all of this from within a Mozilla plugin.
I create the PDFDocument, and put it into a PDFView, then I call
[printView printWithInfo: [NSPrintInfo sharedPrintInfo] autoRotate: YES];
The print dialog comes up (as a separate window, instead of panel. I assume that that comes from being inside a mozilla window, so I wasn't too worried about it. The dialog shows my document, and I can page through it correctly, and everything looks good.
However, when I hit "Print" the dropdown with "Layout" etc becomes empty, and the view under that becomes empty. The window doesn't disappear, and the document doesn't print. Hitting Cancel does exactly the same thing. The only thing I can do then is force-quit Mozillla.
I based the program off of PDFKitLinker2 from the apple dev site, and that program works. But I can't see any significant differences between it and my version.
Any suggestions on where to look?
thanks.
EDIT: Yes, I know that this is pretty much an exact duplicate of Printing Off-screen PDFViews but that never got a sufficient answer... (And I didn't notice it until just now...)
Sounds like you have a memory management issue here. Have you checked the console log to see if there's an exception being thrown? How are you creating your PDFView?
But why not do it the way WebKit does it?
Specifically, declare a category on PDFDocument
#interface PDFDocument (PDFSecretsIKnowViaWebKit)
- (NSPrintOperation *)getPrintOperationForPrintInfo:(NSPrintInfo *)printInfo autoRotate:(BOOL)doRotate;
#end
Then when you want to print your PDFDocument simply get an NSPrintOperation from it and run it.
NSPrintOperation *op = [myPDFDoc getPrintOperationForPrintInfo:info autoRotate:YES];
[op runOperation];
// [op runOperationModalForWindow:delegate:didRunSelector:contextInfo:] if you have a window to attach it to
This works for me too. I've verified that getPrintOperationForPrintInfo:autoRotate: exists and appears to work correctly on 10.4, 10.5 and 10.6.