Setting text item delimiters in Cocoa-Applescript App
Does anyone know of a problem with text item delimiters in a Cocoa-Applescript App. This is in Xcode 4.5.2 and Mountain Lion
the following code seems to fail to set the text item delimeter to + when I run it in Coca-AppleScript
-- TSTAppDelegate.applescript
-- Test Text item Delimiters
-- Created by Frank Caggiano on 12/22/12.
-- Copyright (c) 2012 Frank Caggiano. All rights reserved.
script TSTAppDelegate
property parent : class "NSObject"
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
tstTxtDel()
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
on tstTxtDel()
set text item delimiters to "+"
set d to "-s http://www.nietzschefamilycircus.com"
set r to do shell script "curl " & d & " | ~/Desktop/try.pl"
display dialog "r is " & r
set rr to every text item of r
display dialog "rr " & rr
display dialog "curl " & first text item of rr & " -o "
end
end script
However if you put the tstTstDel() function in the Applescript editor it works as expected.
The try.pl script is
#!/usr/bin/perl
$s ="";
while (<>) {
$s .= $_;
$s =~ m{class="comic"(.*)<div class="footer">}si;
($link, $caption,$jj) = ($1 =~ m{<img src="(.*)" alt=.*class="quote">(.*)(</div>.*</div>)}si);
print $link, "+", $caption, "\n";
I know this worked in the past. The Coca-Applescript app was written at least as far back as Snow Leopard. The site I am parsing changed their format and I was updating the app as a means to learn the new Coca-Applescript environment.
Any help appreciated
OK found it, I needed to use
set Applescript's text item delimiters to "+"
instead of just
set text item delimiters to "+"
I suppose it is a scoping thing.
Similar Messages
-
Cocoa Applescript can't use AppleScript's text item delimiters
Here is my code
if (track_name_html as text) contains (publisher_name as text) then
try
set s to track_name_html as text
set AppleScript's text item delimiters to "- "
set track_name1 to text item 2 of s
on error
set track_name1 to track_name_html as text
end try
else
set track_name1 to track_name_html as text
end if
track_name_ui's setStringValue_(track_name as text)
When I try to log track_name it returns blank. It's very important for my Cocoa-Applescript App.
Thnaks in advanceAfter looking documention I found insertText()
Then I make a handler for quick insertion to text view
on statusin(statustx)
set my statuseditable to true
set timetx to do shell script "date +'%H:%M'"
status's insertText_(timetx & " - " & statustx & return)
set my statuseditable to false
end statusin -
Text item delimiters in SnowLeopard's AppleScript
In SnowLeopard's AppleScript, the statement
set xxx to AppleScript's text item delimiters
is no longer recognized, i.e. "AppleScript's" and "text item delimiters" are nor longer recognized upon compilation.
This always worked before (and was recommended by Apple).
Can anyone indicate what has changed, please?It was just the one line.
Actually, it does seem to work. I was misled by the fact that when I compiled in AppleScript Editor, the words "AppleScript" and "text item delimiters" did not change context coloring (i.e. did not seem to be recognized). I don't know why that should be. Execution was correct nevertheless.
Thanks -
Linked list to string coercion doesn't use text item delimiters: bug?
set AppleScript's text item delimiters to {"; "} -- well-known technique
{1, -1, "c", "d"} as string -- curly braces specify a vector, delimiters work
-- result: "1; -1; c; d"
{1, -1, "c", "d"} as linked list as string -- if coerced to linked list, delimiters ignored
-- result: "1-1cd"
[1, -1, "c", "d"] as string -- square brackets specify a linked list, delimiters ignored
-- result: "1-1cd"
[1, -1, "c", "d"] as vector as string -- coercing linked list to vector first works
-- result: "1; -1; c; d"Hello
It appears that linked list to string coercion does not respect the AppleScript's text item delimiters which are set to list of Unicode text. (Unicode TIDs have no effects in coercion as if it were set to {""})
I can confirm this behaviour in both AppleScript 1.8.3 (OS9) and 1.9.1 (OSX10.2.8) at hand.
So it has been as such for a long time. Bug I'd call it.
By the way, although this is not the point, linked list is a historical residue and of little use in real scripting. After all, it is much slower than vector with appropriate coding. So we may always coerce it to vector without losing anything.
Regards,
H
Linked list to string coercion & AppleScript's text item delimiters (TIDs).
When AppleScript's TIDs are set to list of Unicode text,
the TIDs have no effect in coercion from linked list to string as if they were set to {""}.
set aa to [1, 2, "a", "b"]
--set aa to {1, 2, "a", "b"} as linked list
set t1 to list2text(aa, ";") -- "1;2;a;b" -- in pre-AppleScript 2.0
set t2 to list2text(aa, ";" as Unicode text) --"12ab"
return {t1, t2}
on list2text(aa, delim)
list aa : source list
string delim : a text item delimiter
return string
local astid, astid0, t
set astid to a reference to AppleScript's text item delimiters
set astid0 to astid's contents
try
set astid's contents to {delim}
--set t to aa as string
--set t to aa as Unicode text
set t to "" & aa
set astid's contents to astid0
on error errs number errn
set astid's contents to astid0
error errs number errn
end try
return t
end list2text -
I have a file name with this convention, a project code like such.
AR123 smith, bob EM v1.mov
I need to change the EM to AM.
how do I do it. thanks for any help.There is a decent text item delimiters tutorial at MacScripter - you can replace text by breaking a string apart using one set of delimiters and putting it back together again using another. The following example will rename files using your example:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
tell application "Finder" to repeat with SomeFile in (choose file with multiple selections allowed) -- get file(s)
set TheName to name of SomeFile -- get the name
considering case -- pay attention to the case of the text in the following statements
set TempTID to AppleScript's text item delimiters -- save the current delimiter
set AppleScript's text item delimiters to "EM" -- the text to replace
set NewName to text items of TheName -- break the text apart at each delimiter
set AppleScript's text item delimiters to "AM" -- the replacement text
set NewName to NewName as text -- put the text back together with the delimiter
set AppleScript's text item delimiters to TempTID -- restore the original delimiter
end considering
if NewName is not equal to TheName then -- rename if necessary
tell application "Finder" to set the name of SomeFile to NewName
end if
end repeat
</pre> -
Set Text Item To SQL Query Result
I am trying to set a text item to a SQL query result. Something like the following:
(I am trying to accomplish this in the SOURCE portion, set to 'SQL Query' source type, of the text item properties)
SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
This only displays as the literal text when the application renders and not the value from the SQL query.
I apologize if this has already been posted but I could not find what I am looking for. I have seen posts that reference a pre-region computation but do not know the exact steps to accomplish the results I want.
Thanks in advance for anyone's time to help me with my issue.
KyleScott,
The literal that displayed (I have fixed it) was the actual SQL statement: SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
I have resolved the issue, using SQL Query as the "Source Type" and Always, replacing any existing value in session state as the "Source Used" for the properties of the item.
What I was trying to accomplish is a search text item that would return the data for that record in a table into other text items, for each column in that record, for update; based on the search text item as a unique SQL query search for that record.
Thank you for your quick reply!
Kyle -
Hello, I'm using Oracle 9i both as Ids and database
This is what I'm having-
2 data blocks 1st is database block and 2nd is control block.
database block named EMP is associated with EMP table and Control block named CTRLB have 2 item 1st is a text item and 2nd is a Push button.
This is what i wanted-
At first i wish to show the CTRLB items when user provide an input in "Text item" say a number and press the button the Values from "Text Item " is placed in Emp blocks Department_id item and a query is executed (act as where filter) and return only the employees records within that Department_id
This is what i done so far-
i write a trigger" when button press" on push button item and entered the following code
NEXT_BLOCK;
ENTER_QUERY;
:EMP.DEPART_ID:=:CTRLB.PBT;
EXECUTE_QUERY;
but it donot make any query.
but when i use the execute query from the menu(the built in provided by oracle in applet) it works. i mean there is no problem in database connection or mapping. only the button is not working.
So what i'm doing wrong or 'What i should do now to have it worked
thank you
Message was edited by:
Rainbow
Message was edited by:
RainbowHello,
You could use the DEFAULT_WHERE clause of the based block, so that you just have to execute the query:
Set_Block_Property( 'EMP', DEFAULT_WHERE, 'DEPART_ID = :CTRLB.PBT' ) ;
Go_Block('EMP');
Execute_Query ;Francois -
How can I detect when a text field changes in Cocoa-Applescript?
I'm working on an application where I have one text field, and below it, a "Send" button. When the button is pressed, is sends whatever is typed in the field to all the user's Skype contacts. I have to prevent the user from sending a blank message to all contacts, so I have to change the button's setEnabled. I've been using an NSTimer to check every second, which works, but it lags my application hugely. Is there any handler that is run whenever text is added or deleted? Perhaps something like:
on myTextFieldDidChange_(aNotification)A specific text field is not used in the handler call - the delegate method is called for all text fields. In the case where you have several text fields, you can get the notification's object, for example:
on controlTextDidChange_(aNotification) -- a text field changed, so check it out
set thisTextField to aNotification's object() -- the current control being changed
set theText to thisTextField's stringValue()
log theText
-- whatever
end controlTextDidChange_
Note that you need to connect the text field's delegate outlet to your AppDelegate (or whatever class you are using for the delegate). -
How can I prevent my fullscreen app from closing when escape is pressed in Cocoa-Applescript?
How can I prevent my fullscreen Cocoa-Applescript app from being closed when a user presses escape?
Actually, in testing something else with Thunderbird as the receiving email client, I found that blanks in the Full Name entry box works when the recipient does not have a history with you. My earlier tests were from one account to another of my accounts, but viewing the received message in Mail. Mail knew the address so added the Full Name from history. The Thunderbird I was testing another issue with, was a virgin installation, and had the same recipient account, but not the sending one, setup. In Thunderbird only the actual email address came in, and no name.
Ernie -
Using an applescript in a cocoa-applescript application
Hello,
I have an applescript I am trying to use in a project. I have everything set up so when you click a button it runs this:
repeat
set statusOld to checkStatus()
set statusNew to checkStatus()
repeat while statusOld is equal to statusNew
delay 1
set statusNew to checkStatus()
end repeat
if statusNew is true then
display dialog "Device Added - put some real code here"
else
display dialog "Device Removed - put some real code here"
end if
end repeat
on checkStatus()
set myString to do shell script "system_profiler SPBluetoothDataType"
if myString does not contain "DR-BT101" then
return false
else
set AppleScript's text item delimiters to "name:"
set myList to the text items of myString
set numberOfDevices to count of myList
set counter to 1
repeat numberOfDevices times
if item counter of myList contains "DR-BT101" then
if item counter of myList contains "Connected: Yes" then
return true
else if item counter of myList contains "Connected: No" then
return false
else
display dialog "Error Parsing"
end if
end if
set counter to counter + 1
end repeat
end if
end checkStatus
However, It will not run because of the "on checkStatus()" part. How would I fix this and also make it so the user can stop running the script?It's pretty easy to block the user interface when converting AppleScripts that use repeat loops. For an example of the other approach that uses a repeating timer, create a new example project (named "Timer Example") with the following script. Then from *Interface Builder*, create a couple of buttons (named "Start" and "Stop") and connect the buttons to the doButtonStuff action. You can see the progress of things in the run console.
The main difference is that instead of a tight repeat loop that hogs the entire run loop, a timer is set up to check things every once in a while. Since the application is now free to do other things in between firings of the timer, your user interface stays responsive.
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #DAFFB6;
overflow: auto;"
title="this text can be pasted into Xcode 3.2.x (Snow Leopard)">
# MARK: -
# MARK: Application Properties
property thisApp : current application
property NSTimer : class "NSTimer"
property NSRunLoop : class "NSRunLoop"
script Timer_ExampleAppDelegate -- change the name to match your example project if needed
# MARK: -
# MARK: Script Properties
property parent : class "NSObject"
property myTimer : missing value -- this will be a repeating timer
property statusOld : missing value -- this will be the original status
# MARK: -
# MARK: Interface Builder Actions
on doButtonStuff_(sender)
log "doButton..."
set theButton to (sender's |title| as text)
if theButton is "Start" then
log "timer started..."
if myTimer is missing value or not myTimer's isValid() then -- check if the timer is already running
set myTimer to NSTimer's timerWithTimeInterval_target_selector_userInfo_repeats_(2, me, "doCheck", missing value, true) -- create
NSRunLoop's mainRunLoop()'s addTimer_forMode_(myTimer, thisApp's NSDefaultRunLoopMode) -- start the timer
end if
else if theButton is "Stop" then
log "timer stopped..."
myTimer's invalidate() -- stop the timer
end if
end doButtonStuff_
# MARK: -
# MARK: Script Handlers
on doCheck()
script check
on checkStatus()
log "checkStatus..."
set myString to (do shell script "system_profiler SPBluetoothDataType")
if myString does not contain "DR-BT101" then return false
set tempTID to AppleScript's text item delimiters -- save existing delimiters
set AppleScript's text item delimiters to "name:"
set myList to the text items of myString
set AppleScript's text item delimiters to tempTID -- restore delimiters
repeat with anItem in myList
set anItem to contents of anItem -- dereference list item
if anItem contains "DR-BT101" then
if anItem contains "Connected: Yes" then
return true
else if anItem contains "Connected: No" then
return false
end if
end if
end repeat
display dialog "Error Parsing" -- oops
end checkStatus
end script
repeat
if statusOld is missing value then set statusOld to check's checkStatus()
set statusNew to check's checkStatus()
if statusNew is equal to statusOld then return -- no change
if statusNew is true then
-- myTimer's invalidate() -- stop the timer
display dialog "Device Added - put some real code here"
else
-- myTimer's invalidate() -- stop the timer
display dialog "Device Removed - put some real code here"
end if
end repeat
end doCheck
end script</pre> -
this does not work.
I need to extract the name of the file dropped onto the droplet.
can anyone help.
on open the_files
repeat with a_file in the_files
tell application "Finder"
set AppleScript's text item delimiters to {":"}
-- display dialog a_file as string
--set the_file to a_file as string
get last text item of a_file as string
display dialog a_file as string
end tell
end repeat
end openI got this to work so the result gives me the just file name (AR155Scott, Bobby Full mix.png), now I need to extract out just the AR155 part of the file name. any help would be appreciated. Thanks.
repeat with a_file in the_files
tell application "Finder"
set AppleScript's text item delimiters to {":"}
set the_file to a_file as string
set the_project to the last text item of the_file
display dialog the_project as string -- AR155 Scott, Bobby Full mix.png
--set the_project to last text item of a_file as string
-- display dialog the_project as string
end tell
end repeat -
Set Disable or Expiry Date for web app item via Edit form
I have a user that wants to delete a web app item from a secure zone edit form, but they are not the owner of that web app item. All items in the web app were imported via a csv file and hence do not have a 'submitted by' user id assigned.
Is it possible to Disable a web app item using a web app Edit form? or alternatively, is it possible to set the Expiry Date of a web app item using a web app Edit form?
Thanks
DaveSorry Brian, but I'm not sure that answers my question.
Sure, I can create a single web app item for every single client of my customer, manually.
Sure, I can create and 'allocate' that single web app item to each customer manually.
I pray the customer doesn't have hundreds of clients. And I would have to teach my customer how to do this convoluted process for every new client.
But the one thing this doesn't do is answer the question of updating the value of units held.
It seems the order module remains the closes to what I am looking for in that it allows an equation, and is automatically customer specific.
However, I am looking for a way to achieve a single daily update by the customer as to the value of the units held by each client. This can be done via the product module - update price. But this does not update existing orders. Exisitng orders are fixed at the price on the day. The customer wants to update the value once, in one place, and have that amend all existing 'orders' to reflect the new total value of units held by each individual client, and to have this show in each client's member area.
If you can think of a way of doing this in webapps or via the order module, this is what I am looking for. Anyone? -
Hi,
I have a text item. I also have an application item.
I want to set this text item with the value of the application item every time the page is redirected.
Is thos possible????
How do I do this?
Plase suggest.
Thanks.
Edited by: machan on Feb 9, 2010 1:03 PMMachan,
You should be able to set the Text item with the value of the Application item if Source Type = "Item (Application or Page Item Name)".
Ittichai -
Setting the text of a text item
Hi.
I am new to forms. This must be simple! How do you set the contents of a text item programmatically at run time? I want to put the value of a parameter into a text item that appears on my form.
Thanks.In an appropriate trigger (WHEN-NEW-FORM-INSTANCE, perhaps), you can set the value of a field on a block by simply assigning a value to it, thus:
:BLOCK.FIELD := value ;
Remember to make sure the datatypes are compatible by casting if necessary. -
Setting the cursor at the end of a text item Forms 10g
Is there a way in 10g forms to set the cursor at the end of the text item without highlighting the text.
I have a text item field when I query it and tab to the field, it highlights the whole text inside the block item. Users sometimes type without thinking so, we made it set the cursor at the end.
I know in 6i forms there was a client package (d2kwutil) that accomplished this and if I have too, I'll use it via the WebUtil. I just was not sure if there was anything in 10g forms that accomplished the same task.
Any help is appreciated.
ChrisHello,
You can also use the good old win_api_shell.sendkeys() d2kwutil function, that works also fine with Web versions.
For instance, in a When-New-Item-Instance trigger:
win_api_shell.sendkeys(get_window_property('WINDOW1',window_handle),'{End}',TRUE); Francois
Maybe you are looking for
-
Questions w.r.t essbase migration
Hi, I have two queries: 1. We are going to migrate from essbase 7.1.6 to 11.1.2.2. We will follow manual approach i.e create new app in 11.1.2.2 and move all object and data to new app. I want to know is there any non compatibility between these two
-
HT1923 itunesHelper was not installed correctly. please reinstall itunes. error 7
I am trying to install new version of itunes. It kept telling me that it was not installed properly. My os system is window 7. I unstalled apple related software through control panel and reinstalled new one. But still erros. Please help!!
-
If I use an app to remove duplicate pix does the app read content or only the file name such as IMG
If I use an app to remove duplicate pix does the app read content or only the file name such as IMG. I have some 2500 pix and the thought of trawling thru them toremove duplicates is mind numbing. If the apps read the content then I am ok abou
-
For almost thirty years drag-and-drop has been an Apple standard. Now, in iPhoto '11 I want to create a so-called "Album" of some photos chosen from an "Event." Naturally I create an album, select a number of photos and drag them into the new Album.
-
Error generating screen commentary files - OPM 10.2
Hi everyone, I'm getting an error generating a screen commentary files. Link to error: The commentary files could not be created. PLease ensure that your configuration settings are correct and you have write permission to the specified commentary dir